【发布时间】:2015-05-02 00:59:23
【问题描述】:
我被困在一个需要我转换输入年份并在几秒钟内打印结果的任务上。运行该函数时收到的错误消息是:
'*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)
【问题讨论】:
-
字符串中没有
%用于替换seconds... -
如果您询问生日,您可以获得更精确的值,例如,从今天到 1978 年 3 月 1 日(生日)之间有 13514 天,因此从那时起经过了
13514*86400 + 18SI 秒(同时日(考虑到与两个日期相对应的 UTC 偏移量的可能差异))。18是自 1978 年 3 月 1 日以来的闰秒数。
标签: python python-3.x time