我正在做一個貨幣轉換器。我如何讓Python接受整數和浮點數?如何接受int和float類型的輸入?
這是我做的:
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()
的我是如何做的簡單的例子:
number = input("Enter a number: ")
if number == int:
print("integer")
if number == float:
print("float")
這兩個不工作。
我改變你的標題和標題爲小寫。請不要向我們大喊:) – gyre
'如果type(number)是int'但是這總是錯誤的,因爲'number'將始終是一個字符串。 –
@ juanpa.arrivillaga不,它不是。他使用'input'從用戶讀取,'type(numer)'是'str'。 – direprobs