-1
这是我的代码:为什么在Python中为我工作?
for count in range(NOI):
ig=input("enter a GTIN code: ")
while ig!=("21356797"):
print("incorrect")
ig=input("enter a GTIN code: ")
count =count+1
,这是输出:
21356797
13246785
31325974
45689413
34512340
56756777
how many items do you want to buy?: 1
enter a GTIN code: 21356797
>>>
这就是我想要的。然而,一旦我把或我while循环,我不能让它像第一部分的工作:
while ig!=("21356797" or "13246785"):
print("incorrect")
ig=input("enter a GTIN code: ")
count =count+1
,这是输出:
how many items do you want to buy?: 1
enter a GTIN code: 13246785
incorrect
enter a GTIN code: 21356797
>>>
在[“21356797”,“13246785”]中可能'while ig!=(“21356797”或“13246785”):'=>''''':'在两个字符串之间使用'或'因为字符串不是布尔值(虽然它们可以被强制为这样,这实际上并不是你想要的)。 –
'“21356797”或“13246785”'是“21356797”,请在python中查找or运算符。你必须做'ig!= ...或者ig!= ...' – Jasper
@Jasper:如果你使用'!=',你需要''和'条件一起,而不是'或'它们。否则,任何事情都不会通过,因为它始终不等于其中一个值。 – ShadowRanger