未加载基本Python if语句

未加载基本Python if语句,python,Python,我试图让代码告诉我我选择了什么,但它无法识别最后的if语句,也无法打印任何内容 任何帮助都会很好 谢谢:)正确的缩进是Python的基本组成部分。按照您编写问题的方式,else语句适用于while循环(这是完全有效的),而不是循环中的if语句。另外,最后的if语句应该使用elif,这是elseif的Python缩写 下面是它的外观: print ("Welcome teaacher") while True: Class = input("Which class (1, 2 or 3)

我试图让代码告诉我我选择了什么,但它无法识别最后的if语句,也无法打印任何内容

任何帮助都会很好
谢谢:)

正确的缩进是Python的基本组成部分。按照您编写问题的方式,
else
语句适用于
while
循环(这是完全有效的),而不是循环中的
if
语句。另外,最后的
if
语句应该使用
elif
,这是
elseif
的Python缩写

下面是它的外观:

print ("Welcome teaacher")  
while True:
   Class = input("Which class (1, 2 or 3) would you like to look at?")
    if Class.lower() not in ('1', '2', '3'):
    print("Not an appropriate choice.")
else:
    break
while True:
    print("Which method would you like to view by?")
    Method = input("Type '1' for average, '2' for highest score or '3' for alphabetical")
    if Class.lower() not in ('1', '2', '3'):
        print("Not an appropriate choice.")
else:
    break
if Method == 1:
    print("You have chosen Class" +Class+ " average")
if Method == 2:
    print("You have chosen Class" +Class+ " highest score")
if Method == 3:
    print("You have chosen Class" +Class+ " alphabetical")

正确的缩进是Python的一个基本部分。按照您编写问题的方式,
else
语句适用于
while
循环(这是完全有效的),而不是循环中的
if
语句。另外,最后的
if
语句应该使用
elif
,这是
elseif
的Python缩写

下面是它的外观:

print ("Welcome teaacher")  
while True:
   Class = input("Which class (1, 2 or 3) would you like to look at?")
    if Class.lower() not in ('1', '2', '3'):
    print("Not an appropriate choice.")
else:
    break
while True:
    print("Which method would you like to view by?")
    Method = input("Type '1' for average, '2' for highest score or '3' for alphabetical")
    if Class.lower() not in ('1', '2', '3'):
        print("Not an appropriate choice.")
else:
    break
if Method == 1:
    print("You have chosen Class" +Class+ " average")
if Method == 2:
    print("You have chosen Class" +Class+ " highest score")
if Method == 3:
    print("You have chosen Class" +Class+ " alphabetical")

请修复缩进,并提供更好的缩进。可能的重复指出,它不会在
行上中断,而在True
行上中断(它永远不会达到False状态)。也许你想将
else
if
配对?谢谢你帮助lotFix了你的缩进并提供了一个更好的缩进。可能的重复指出,当为True行时,它永远不会在
行上中断(它永远不会达到错误状态)。也许你想将
else
if
s配对?谢谢你的帮助,洛蒂特仍然无法识别底部的if语句和所有更改。我忘了你的输入是字符串,所以检查方法应该是“1”、“2”或“3”。我将用更新编辑答案。谢谢,我在这个简单的错误上被困太久了。它仍然无法识别底部带有所有更改的if语句。我忘记了您的输入是字符串,因此check-on方法应该用于“1”、“2”或“3”。我将用更新编辑答案。谢谢你,我在这个简单的错误上坚持了太久