Python if、elif语句的语法错误
我很难让这个代码正常工作。它不断出现SyntaxError:无效语法Python if、elif语句的语法错误,python,eclipse,syntax-error,Python,Eclipse,Syntax Error,我很难让这个代码正常工作。它不断出现SyntaxError:无效语法 adult = int(input("No adults:") child = int(input("No children:") type = int(input("Well done or Rare:") if adult < 0: print("Enter number >=0) elif child < 0: print("Enter number >=
adult = int(input("No adults:")
child = int(input("No children:")
type = int(input("Well done or Rare:")
if adult < 0:
print("Enter number >=0)
elif child < 0:
print("Enter number >=0)
elif type != "W" or type != "R":
print("error")
成人=int(输入(“无成人:”)
child=int(输入(“无子项:”)
type=int(输入(“做得好或很少:”)
如果成人<0:
打印(“输入编号>=0)
elif child<0:
打印(“输入编号>=0)
elif类型!=“W”或类型!=“R”:
打印(“错误”)
如果用户输入的数字正确,我希望它转到行中的下一个问题。如果用户输入的数据不正确,我希望错误消息,然后重复相同的问题
谢谢!!您缺少一些括号:
int(input("No adults:")
^
int(input("No children:")
^
int(input("Well done or Rare:")
^ need another to close int()
此外,请确保缩进正确:
if adult < 0:
print("Enter number >=0)
elif child < 0:
print("Enter number >=0)
elif type != "W" or type != "R":
print("error")
如果成人<0:
打印(“输入编号>=0)
elif child<0:
打印(“输入编号>=0)
elif类型!=“W”或类型!=“R”:
打印(“错误”)
试试这个:
adult = int(input("No adults:"))
child = int(input("No children:"))
type = int(input("Well done or Rare:"))
if adult < 0:
print("Enter number >=0")
elif child < 0:
print("Enter number >=0")
elif type != "W" or type != "R":
print("error")
成人=int(输入(“无成人:”)
child=int(输入(“无子项:”)
type=int(输入(“做得好或很少:”)
如果成人<0:
打印(“输入编号>=0”)
elif child<0:
打印(“输入编号>=0”)
elif类型!=“W”或类型!=“R”:
打印(“错误”)
将其与您的代码进行比较
您的代码包括:缺少)
,“
,缩进错误
注意:使用
类型
作为变量将屏蔽函数或定义变量的块范围内的内置函数“type”。因此,虽然这样做不会引起语法错误,但似乎是一种糟糕的编程体验。在打印(“输入数字>=0”)中缺少双引号。