ELIF, ELSE syntax error python 3.2.1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def magic_n(guess2): #Function, have someone guess if number is 7, max 5 tries magicn2 == 7 tries = 0 while (tries < 5) and (guess2 != magicn2): if guess < 7 : tries = tries + 1 print("Too Low") guess2 = int(input("Give me another number since the last one was too high :")) elif guess > 7: tries = tries + 1 print("Too high") guess2 = int(input("Give me another number since the l ast one was too low :") else : print("Good job you got it") |
guess2 = int(输入("请给我一个号码:")
打印(magic_n(guess2)
如果这种询问方式不正确,请先道歉,第一次使用堆栈溢出
是缩进....
当你使用python时......我建议你看看PYCHARM,因为你可以避免将来出现这样的错误。 我经常使用它并自动格式化。
https://www.jetbrains.com/pycharm/
标识不正确,在"else"之前需要再加一个括号。
所以它会是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | def magic_n(guess2): magicn = 7 tries = 0 while (tries < 5) and (guess2 != magicn): if guess2 < 7: tries += 1 print("Too Low") guess2 = int(input("Give me another number since the last one was too high :")) elif guess2 > 7: tries += 1 print("Too high") guess2 = int(input("Give me another number since the l ast one was too low :")) else: print("Good job you got it") |
第12行:
1 | guess2 = int(input("Give me another number since the l ast one was too low :")) //bracket missing |
缩进必须在python中是正确的。在python中没有}所以代码片段需要了解我的块在哪里开始以及它在哪里结束
所以
1 2 3 4 5 6 7 8 | if condition: ........ ........ elif condition : ........ ........ else : ........ |