我不明白在python3中这个代码的“语法错误:无效语法”是什么意思

2024-10-02 00:36:34 发布

您现在位置:Python中文网/ 问答频道 /正文

#ask user for input
sInput = int(input("Enter the number of seconds. ")

#calculations
minutes = sInput / 60
minutes = int(minutes)
totalHours = int(totalMinutes/60)

错误显示为:

分钟=输入/60

^

语法错误:无效语法


Tags: ofthenumberforinputaskintseconds
2条回答

这是你的错误:

#ask user for input
sInput = int(input("Enter the number of seconds. ")

你误用了右括号。 更正为:

#ask user for input
sInput = int(input("Enter the number of seconds. "))

你在前一行忘了一个)!你知道吗

sInput = int(input("Enter the number of seconds. ")
                                                   ^ here!

Python解析器的有趣之处在于,当有未闭合的圆括号或大括号时,它将扩展逻辑行,直到所有这些都闭合。然后,该注释被忽略,它发现minutes之间没有任何运算符。因此会出现语法错误,就像您编写:

sInput = int(input("...") minutes = sInput / 60 minutes = ...
                          ^ syntax error!

相关问题 更多 >

    热门问题