python - 在Python中将年转换为秒

标签 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)

最佳答案

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

相关文章:

python - 如何在Ubuntu上使用多个版本的NLTK?

python - 104, 'Connection reset by peer' 套接字错误,或何时关闭套接字会导致 RST 而不是 FIN?

python - 运行Python子进程直到不再发生错误?

Python PY 文件不反射(reflect)更改

python - 在 LAMP (CentOS) 服务器上运行 .py 文件 - 从 PHP 开发人员的角度来看

c# - .Net 中的闹钟应用程序

javascript - 如何在 JavaScript 中获取浏览器时区

matlab - Simulink - 每 30 秒输出 1,否则输出 0

python - 根据时间戳将 txt 文件数据分割成 24 小时的 block

python-3.x - python : Why is entry set to the value of 1