Ich mache einen Währungsrechner. Wie bekomme ich Python, um sowohl Integer als auch Float zu akzeptieren?Wie akzeptiere ich die Eingabe von int und float?
Dies ist, wie ich es tat:
def aud_brl(amount,From,to):
ER = 0.42108
if amount == int:
if From.strip() == 'aud' and to.strip() == 'brl':
ab = int(amount)/ER
print(ab)
elif From.strip() == 'brl' and to.strip() == 'aud':
ba = int(amount)*ER
print(ba)
if amount == float:
if From.strip() == 'aud' and to.strip() == 'brl':
ab = float(amount)/ER
print(ab)
elif From.strip() == 'brl' and to.strip() == 'aud':
ba = float(amount)*ER
print(ba)
def question():
amount = input("Amount: ")
From = input("From: ")
to = input("To: ")
if From == 'aud' or 'brl' and to == 'aud' or 'brl':
aud_brl(amount,From,to)
question()
einfaches Beispiel, wie ich es tat:
number = input("Enter a number: ")
if number == int:
print("integer")
if number == float:
print("float")
Diese beiden funktionieren nicht.
Ich habe Ihren Titel und Ihre Überschriften in Kleinbuchstaben geändert. Bitte unterlasse es uns nicht anzuschreien :) – gyre
'wenn Typ (Nummer) int 'ist Aber das wird immer falsch sein, da' Nummer 'immer eine Zeichenkette sein wird. –
@ juanpa.arrivillaga nein ist es nicht. Er benutzt 'input', um vom Benutzer zu lesen,' type (numer) 'ist' str'. – direprobs