我正试图用python编写一个ATM机的程序。但是关于输入的内容,它只是说卡片输入成功
inputCard = input("Welcome to the atm machine, please insert your credit card (Type 'Yes' when you have done so) ")
if inputCard == ['No', 'no']: #checks if card has been entered
print ("Please retry")
else:
print ("Card is successfully inputed") `
谢谢
您正在将“输入卡”与列表进行比较。尝试:
相等运算符
==
比较输入(字符串)是否等于右侧(列表)。直观地说,一个列表永远不会等于一个字符串因此,使用
in
操作符查看答案是否在可能的选项中:或者,将答案转换为小写,然后使用
==
:这种方式将接受
no
、No
、NO
和nO
inputCard
是str,["NO","no"]
是list。它们将不相等。您可以这样尝试或者
相关问题 更多 >
编程相关推荐