我正在尝试制作一个预算程序,我需要对其进行编程,以便每当我运行代码时我都可以将我那周赚的钱添加到总额中。我希望能够存储最新输入的金额pay_this_week并将其添加到total每次运行代码时。我应该制作pay_this_week一个列表并将其附加到总计中吗?
这是代码:
def money_earnt():
total = int()
while True:
try:
pay_this_week = int(input("How much money did you earn this week? "))
break
except ValueError:
print("Oops! That was no valid number. Try again...")
pay_this_week_message = "You've earnt £{0} this week!".format(pay_this_week)
total = pay_this_week + total
total_message = "You have earned £{0} in total!".format(total)
print(pay_this_week_message)
print(total_message)
money_earnt()
婷婷同学_
有只小跳蛙
相关分类