[英]How can I fix this python problem with lists
num1 = [int(input()), int(input()), int(input()), int(input()), int(input()), int(input()), int(input())]
for i in range(0, 3):
if num1[i] == int(8) or int(9):
print("Ignore")
print(num1[i])
break
Just wondering for this code, I input 1,2,3,4,5,6,7 for the list.只是想知道这个代码,我输入了 1,2,3,4,5,6,7 作为列表。 And it returns and prints ignore, but the for loop looping the first 4 numbers which do not equal to 8 or 9. Can someone please explain this phenomenon thanks.
它返回并打印忽略,但 for 循环循环前 4 个不等于 8 或 9 的数字。有人可以解释这种现象吗谢谢。
In line 3 you say在第 3 行你说
if num1[i] == int(8) or int(9)
The problem with this is that python splits the boolean as (num[i] == int(8)) or (int(9))
问题在于python将布尔值拆分为
(num[i] == int(8)) or (int(9))
int(9)
is True (all non-zero numbers default to True) so your program will print("Ignore")
no matter what the number is int(9)
为 True(所有非零数字默认为 True),因此无论数字是多少,您的程序都会print("Ignore")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.