Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 程序正在停止,即使条件为';没有遇到_Python_Python 3.x - Fatal编程技术网

Python 程序正在停止,即使条件为';没有遇到

Python 程序正在停止,即使条件为';没有遇到,python,python-3.x,Python,Python 3.x,当我按Y或N时,即使我有它,它也会打印“这不是一个选项” 我已将其设置为!=(不等于) 全部代码 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() =

当我按Y或N时,即使我有它,它也会打印“这不是一个选项”

我已将其设置为!=(不等于)

全部代码

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 ")`

您犯了一个错误,只是在未指定条件的情况下放置了
语句。您必须指定另一个条件,而不仅仅是
输入值。在这里,我提供了一个例子

import sys
c = input('do you like piza? Y or N:')
if c.upper() != 'N' or c.upper() != "Y": 
    print ("that wasn't an option")
if c.upper() != 'N' or c.upper() != "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 ")
您还可以通过组合最后2个
(如果是这样的话)来稍微重构代码:

if c.upper() == 'N':
    print("really i thought everybody likes piza.")
    sys.exit()
if c.upper() != 'N' or c.upper() != "Y": 
    print ("that wasn't an option")
    sys.ext()
还有前两个
,如果是这样的话:

if c.upper() == 'N':
    print("really i thought everybody likes piza.")
    sys.exit()
if c.upper() != 'N' or c.upper() != "Y": 
    print ("that wasn't an option")
    sys.ext()
编辑

应替换为
,否则该检查没有意义

凯尔伍德指出了这一点,这要归功于他


希望这有帮助

如果c.upper()!='N'或“Y”-错误,
如果c.upper()!='N'或c.上部()“Y”或:
如果{'Y',N'}中的c.upper()是:…
如果。。。或者“Y”
总是真实的,因为您的条件之一就是
“Y”
,而
“Y”
是真实的。你的意思是
如果c.upper()不在{'N','Y'}:
@Basalex你的意思是
,而不是
c.upper()!='N'或c.上部()“Y”
始终为真。你的意思是
,而不是
@khelwood噢,很好,我一直在寻找语法错误,现在只会更新