我陷入了一项作业,需要我转换几年的输入并在几秒钟内打印结果。运行该函数时收到的错误消息是:
'*TypeError: not all arguments converted during string formatting*'
我真的无法理解出了什么问题......
def ageInSeconds():
"""
Reads the age and converts to seconds.
"""
ageYears = int(input("Tell me your age, please: "))
seconds = ageYears * (365*24*60*60)
print("\nBatman says you age in seconds is: " % seconds)
最佳答案
字符串中缺少 %d
。
print("\nBatman says you age in seconds is: %d" % seconds)
^
你还可以做
print("\nBatman says you age in seconds is:",seconds) # Inbuilt feature of the print function
关于python - 在Python中将年转换为秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28796854/