我不明白这是什么意思;语法错误:无效语法";用于Python 3中的此代码
错误显示为: 分钟=sInput/60 ^ 语法错误:无效语法您在前一行中忘记了一个我不明白这是什么意思;语法错误:无效语法";用于Python 3中的此代码,python,python-3.x,Python,Python 3.x,错误显示为: 分钟=sInput/60 ^ 语法错误:无效语法您在前一行中忘记了一个) #ask user for input sInput = int(input("Enter the number of seconds. ") #calculations minutes = sInput / 60 minutes = int(minutes) totalHours = int(totalMinutes/60) Python解析器的有趣之处在于,当存在未闭合的括号或大括号时,它将扩展逻辑行
)
#ask user for input
sInput = int(input("Enter the number of seconds. ")
#calculations
minutes = sInput / 60
minutes = int(minutes)
totalHours = int(totalMinutes/60)
Python解析器的有趣之处在于,当存在未闭合的括号或大括号时,它将扩展逻辑行,直到所有这些都闭合。然后,该注释被忽略,它会发现minutes
之间没有任何运算符。因此会出现语法错误,就像您编写:
sInput = int(input("Enter the number of seconds. ")
^ here!
这是你的错误:
sInput = int(input("...") minutes = sInput / 60 minutes = ...
^ syntax error!
你错用了一个结束括号。
将其更正为:
#ask user for input
sInput = int(input("Enter the number of seconds. ")
当您在一行开头看到sytax错误时,总是怀疑前一行有问题。我可以推荐一个带有语法突出显示的文本编辑器吗?这往往会使这类错误立即变得显而易见。
#ask user for input
sInput = int(input("Enter the number of seconds. "))