在Python中将年份转换为秒

时间:2015-03-01 17:43:30

标签: python python-3.x time

我坚持要求我转换年份输入并在几秒钟内打印结果的作业。我运行该函数时收到的错误消息是:

'*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)

1 个答案:

答案 0 :(得分:4)

您在字符串中缺少%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