当我运行try-and-except时,有没有一种方法可以消除语法错误


while True:
try:
a = float(input("Enter a number for how long the break between words should be:")
except ValueError:
print("YOu haven't entered a number")
  1. 在我执行它之后:

    File "main.py", line 7
    except ValueError:
    ^
    SyntaxError: invalid syntax
    
  2. 为什么会出现此错误?

此行末尾缺少一个右括号:

a = float(input("Enter a number for how long the break between words should be:")

您在第3行缺少右括号,您的代码应该是:

while True:
try:
a = float(input("Enter a number for how long the break between words should be:"))
except ValueError:
print("You haven't entered a number")

相关内容

最新更新