<分区>
我想插入一个数字,如果我输入 4 以外的任何数字,它会告诉我这是错误的,但如果它是假的,它会告诉我“你赢了,菜鸟。”。但是,当我插入 4 时,它告诉我它不正确。
x = input("Insert a numer: ")
while x != 4:
print("incorrect")
x =input("Insert another number: ")
if x == 4:
print("gg you win, noob")
标签 python
<分区>
我想插入一个数字,如果我输入 4 以外的任何数字,它会告诉我这是错误的,但如果它是假的,它会告诉我“你赢了,菜鸟。”。但是,当我插入 4 时,它告诉我它不正确。
x = input("Insert a numer: ")
while x != 4:
print("incorrect")
x =input("Insert another number: ")
if x == 4:
print("gg you win, noob")
最佳答案
在 Python 3+ 中,input
返回一个字符串,4
不等于 '4'
。您将必须修改为:
while x != '4':
或者使用 int
,如果输入不是 int,请小心检查 ValueError
。
关于Python 输入永远不会等于整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39775273/