在 Python 内将年转换为秒

Convert year to seconds in Python

我被困在一项作业中,需要我转换年的输入并在几秒钟内打印结果。我在 运行 函数时收到的错误消息是:

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