找到你要的答案

Q:Where is the error [closed]

Q:错误在哪里[关闭]

Please, anyone can help me to find and fix the error?

x = 1089
c = int(input("Enter the number you think is")
try:
while c =! x:
if c > 1089:
        print("Very large number")
elif c < 1089:
          print("Very low number")
print("Correct Number! 1089")
except:
    print("Invalid Number!")

请,任何人可以帮助我找到和修复错误?

x = 1089
c = int(input("Enter the number you think is")
try:
while c =! x:
if c > 1089:
        print("Very large number")
elif c < 1089:
          print("Very low number")
print("Correct Number! 1089")
except:
    print("Invalid Number!")
answer1: 回答1:
x = 1089
c = int(input("Enter the number you think is"))# Added bracket here
try:
    while c =! x:
        if c > 1089:
            print("Very large number")
        elif c < 1089:
            print("Very low number")
    print("Correct Number! 1089")
 except:
    print("Invalid Number!")

Python, unlike C-based languages recognises block statements entirely by tabulation. The error is saying that you created a block but didn't put anything in it.

Also, you should change the except statement to:

except TypeError:

So it will only catch TypeErrors thrown by the if statements, and not things like KeyboardInterrupt (especially when using while loops) and SystemExit

x = 1089
c = int(input("Enter the number you think is"))# Added bracket here
try:
    while c =! x:
        if c > 1089:
            print("Very large number")
        elif c < 1089:
            print("Very low number")
    print("Correct Number! 1089")
 except:
    print("Invalid Number!")

Python,不像C语言识别块语句完全由制表。错误是说你创建了一个块,但是没有放任何东西。

此外,您应该更改除声明:

except TypeError:

所以它只会被扔typeerrors if语句,而不是像KeyboardInterrupt(尤其是当使用while循环)和systemexit

python-3.x