我无法理解这个特定的if..else
声明:
print("Do you want to run the next bit of code? Y/N")
n = input()
if n == "Y" or "y":
j = [12, 43, 54, 65]
for i in j:
print (i, end="" "\t")
elif n == "N" or "n":
print("You get numbers if you had pressed Y")
else:
print("That's not an option")
我的问题是,无论我给n
赋什么值,它总是给我Y
或y
的输出。我总是得到输出作为数组编号。这意味着我的状况不正常。那么第一个条件实际上是什么问题呢?
答案 0 :(得分:0)
选中this。 以下代码有效。
print("Do you want to run the next bit of code? Y/N")
n = input()
if n in ["Y", "y"]:
j = [12, 43, 54, 65]
for i in j:
print (i, end="" "\t")
elif n in ["N", "n"]:
print("You get numbers if you had pressed Y")
else:
print("That's not an option")