python解析错误时发生意外的EOF

时间:2020-11-10 13:52:13

标签: python

swim_length =int(input("Please enter a swim length: "))

while swim_length < 0:
print("The length has to be a positive number")
swim_length=int(input("Please enter a positive number: ")

您好,有人可以帮我吗,我确定我犯了一个简单的错误,但我不知道确切的位置。

2 个答案:

答案 0 :(得分:2)

您必须在while循环中添加缩进,并在最后一行的末尾添加括号:

swim_length =int(input("Please enter a swim length: "))

while swim_length < 0:
    print("The length has to be a positive number")
    swim_length=int(input("Please enter a positive number: "))

答案 1 :(得分:0)

在最后一行的第一行中,您错过了结尾)

swim_length=int(input("Please enter a positive number: "))

while循环的主体也需要缩进

while swim_length < 0:
    print("The length has to be a positive number")
    swim_length=int(input("Please enter a positive number: ")