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

问题描述

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: ")

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

解决方法

您必须在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: "))
,

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

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: ")

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...