[英]Why the output is printed “Not Wierd” When the input is 18?
Why the output is printed "Not Wierd" When the input is 18?为什么 output 在输入为 18 时会打印“Not Wierd”?
if __name__ == '__main__':
n = int(input().strip())
if(n%2==0):
if(range(2,5)):
print("Not Weird")
elif(range(6,20)):
print("Weird")
elif(n>20):
print("Not Weird")
else:
print("Weird")
Use n in range(...)
to see if n
is within range.使用
n in range(...)
查看n
是否在范围内。
Issue is with your use or range()
, which returns an iterable, which is a truthy value (if it's not empty), hence your first conditional always being true.问题在于您的 use 或
range()
,它返回一个可迭代的,这是一个真实值(如果它不为空),因此您的第一个条件始终为真。
Update it so you are checking if your number is inside the iterable returned by range()
更新它,以便您检查您的号码是否在
range()
返回的可迭代范围内
...
if(n in range(2,5)):
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.