【发布时间】:2018-04-24 13:30:08
【问题描述】:
即使我有它,当我按 Y 或 N 时,它也会打印“那不是一个选项”
我将其设置为 !=(不等于)
if c.upper() != 'N' or "Y":
print ("that wasn't an option")
if c.upper() != 'N' or "Y":
sys.exit()
完整代码
import sys
c = input('do you like piza? Y or N:')
if c.upper() != 'N' or "Y": print ("that wasn't an option")
if c.upper() != 'N' or "Y": sys.exit()
if c.upper() == 'Y':
print ('Me To')
if c.upper() == 'N': print ("really i thought everybody likes piza.")
if c.upper() == 'N': sys.exit()
name = input("sooo what's ur name? ")
print("that a pretty good name i guess ")`
【问题讨论】:
-
if c.upper() != 'N' or "Y" - is wrong,if c.upper() != 'N' 或 c.upper() != "Y" -
或:
if c.upper() in {'Y', 'N'}: ...。 -
if ... or "Y"总是真实的,因为你的条件之一就是"Y",而"Y"是真实的。你的意思是if c.upper() not in { 'N','Y'}: -
@Basalex 你的意思是
and,而不是or。
标签: python python-3.x