使用 f-strings 因为它将变量更改为字符串并且更容易阅读。所以而不是
print("You have " + str(daysLeft) + "days left until the deadline")
您可以使用它,它会将 daysLeft 更改为字符串。
print(f"You have {daysLeft} days left until the deadline")
还要添加此代码以帮助获得日子。
#convert to days so you don't have the timestamp
daysLeft = daysLeft.days
所以它应该看起来像
import datetime
deadlineInput = input ("What's the deadline for your project? (dd/mm/yyyy):")
deadline = datetime.datetime.strptime(deadlineInput, '%d/%m/%Y').date()
currentDate = datetime.date.today()
daysLeft = deadline - currentDate
#convert to days so you don't have the timestamp
daysLeft = daysLeft.days
#Todo: homework
weeks = # calculate weeks from daysLeft using %
days = # calculate remainder from daysLeft using //
print(f"You have {weeks} weeks and {days} days left until the deadline")
然后返回并重构以删除camelCase并转换为snake_case,例如daysLeft到days_left