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 我如何使它在没有指定名称的情况下工作,它会转到其他位置,为什么elif语句不能工作_Python_Python 3.x - Fatal编程技术网

Python 我如何使它在没有指定名称的情况下工作,它会转到其他位置,为什么elif语句不能工作

Python 我如何使它在没有指定名称的情况下工作,它会转到其他位置,为什么elif语句不能工作,python,python-3.x,Python,Python 3.x,我不确定我做错了什么。我想这样做,如果用户输入的名称不是指定的名称,程序应该在底部打印else语句。我还希望elif语句能够正常工作,因此如果用户输入他们的年龄,那么应该显示正确的打印语句 name = input("What is your name?") if name == "Jean Gray" or "Max Eisanhardt" or "James Howlett" or "Anne Marie": age = int(input("How old are you?")

我不确定我做错了什么。我想这样做,如果用户输入的名称不是指定的名称,程序应该在底部打印else语句。我还希望elif语句能够正常工作,因此如果用户输入他们的年龄,那么应该显示正确的打印语句

name = input("What is your name?")
if name == "Jean Gray" or "Max Eisanhardt" or "James Howlett" or "Anne Marie":
    age = int(input("How old are you?")
    if age <= 12:
    print ('You should be placed in the junior category because you are younger than 12 years old')
    elif age >= 18:
    print ('You should be placed in the senior category because you are older than 18 years old')
    elif age <=17:
    print ('You should be places in the teen category')          
else:
    print("Sorry, that name is not recognised.")
name=input(“你叫什么名字?”)
如果name==“Jean Gray”或“Max Eisanhardt”或“James Howlett”或“Anne Marie”:
年龄=int(输入(“你多大了?”)
如果年龄=18岁:
打印('您应该被列入高级类别,因为您已超过18岁')

如果if语句当前的计算结果始终为true,则应使用以下语法

if a == "value1" or a == "value 2" or a == "value3":
  //do something
if name==“Jean-Gray”或“Max-Eisanhardt”或“James-Howlett”或“Anne-Marie”
:这一行并没有做你认为它能做的事情。如果
name
等于每个字符串,你的测试就是
name
等于
“Jean-Gray”
。if语句中的其他字符串只测试“真实性”。