if else 语句说“ ',' 或 ')' 预期”

时间:2020-12-24 01:24:45

标签: python if-statement

PyCharm 在该行后面的第 8 行(else)中说“无效语法”,它说“',' 或 ')' 预期”

在第 9 行的后面写着“Statement expected found Py:COLON”和“Statement expected found Py:ELSE_KEYWORD”

这里是我使用 Python 3.9 的代码:

distance = " " + input("Please enter the distance the body is supposed to travel here, if unknow leave empty:  ")
speed = " " + input("Please enter the velocity of the body here, if unkown leave empty: ")
time = 0

def get_Time():
    if(distance == " " and speed == " "):
        time = int(input("Please enter the time required for the body to cover the distance: ")
    else:
        time = int(distance)/int(speed)

真的不知道该怎么做才能解决这个问题。我什至不明白问题所在。 希望有人能帮助我。

2 个答案:

答案 0 :(得分:0)

您忘记将右括号放在第 8 行。 应该是这样的:

time = int(input("Please enter the time required for the body to cover the distance: "))

缺少最后一个括号。发生这种情况是因为您已将输入转换为整数,并且转换为:type(),并且您执行了 type(

答案 1 :(得分:0)

错误在这里:

time = int(input("Please enter the time required for the body to cover the distance: ")

开括号两次。 只关闭一次方括号。

需要关闭括号两次。

time = int(input("Please enter the time required for the body to cover the distance: "))
相关问题