Python 3.x Python if语句问题(对编程来说是全新的)

Python 3.x Python if语句问题(对编程来说是全新的),python-3.x,Python 3.x,我想把新加坡元换成美元,但我还是坚持用if语句。它只是无法识别输入()。我在学习,所以我的代码可能真的很蠢,请提前道歉 def converter(scal): return scal * 1.33504 print('Welcome to Smurk Converter ') print('Press 1 to convert SGD to USD :') choice = input() if choice == 1: print('Amount of money y

我想把新加坡元换成美元,但我还是坚持用if语句。它只是无法识别输入()。我在学习,所以我的代码可能真的很蠢,请提前道歉

def converter(scal):

    return scal * 1.33504


print('Welcome to Smurk Converter ')
print('Press 1 to convert SGD to USD :')
choice = input()

if choice == 1:
    print('Amount of money you want to convert: $')
    amount = input()
    his_amount = amount
    print(amount)
    print('If you were to convert that amount SGD to USD...')
    print('It will be: $')
    print(converter(his_amount))

else:
    print('Wrong Input, just enter either 1 or 2')

请提供帮助,谢谢。

如果您使用
input
,它将始终是一个字符串,因此您需要更改以下代码

choice = input()

另外,您需要更改的另一行代码如下

amount = input()


如果使用
input
,它将始终是一个字符串,因此需要更改以下代码

choice = input()

另外,您需要更改的另一行代码如下

amount = input()


当我执行并按1时,它会这样说,欢迎使用Smurk Converter按1将新加坡元转换为美元:1输入错误,只需在我按1时输入1或2。。它转到打印错误的其他位置,输入
input()
返回一个字符串,因此您得到的是字符串值
'1'
,而不是整数值
1
。首先将字符串转换为整数,或与字符串进行比较。当我执行并按1时会显示这一点,欢迎使用Smurk Converter按1将SGD转换为USD:1输入错误,只需在我按1时输入1或2即可。。它转到打印错误的其他位置,输入
input()
返回一个字符串,因此您得到的是字符串值
'1'
,而不是整数值
1
。首先将字符串转换为整数,或与字符串进行比较。