我对编程和练习相当陌生,我决定制作一个程序来计算你还活着多少天,然后将其转换为你还活着的小时数。但是,我不知道如何将天数转换为整数以阻止它在天数和小时数之后打印“天,0:00:00”。
这是我的代码:
from datetime import date
today = date.today()
day = input("Please enter the day you were born on:\n")
month = input("Please enter the month you were born in:\n")
year = input("Please enter the year you were born in:\n")
birthdate = date(int(year), int(month), int(day))
days = today - birthdate
hours = days * 24
print(days)
print(hours)
使用
days = (today - birthdate).days