退出程序
本课属于 Coddy Python 学习旅程的“基础知识”单元。第 69 课,共 77 课。
挑战
简单现在来创建实际的程序!
- 在循环开始前,打印欢迎消息和菜单一次(它们不会在循环内重复打印)
- 创建一个无限的 while 循环(如果不确定怎么做,可以参考提示)
- 在循环的每次迭代中,获取用户的输入,这就是选择(菜单中的 1 - 5)
- 处理第一个情况,如果选择等于 5,就退出程序(循环)并输出:
Exiting the Daily Expense Tracker. Goodbye!亲手试试
print("Welcome to the Daily Expense Tracker!")
# Display menu once
print("\nMenu:")
print("1. Add a new expense")
print("2. View all expenses")
print("3. Calculate total and average expense")
print("4. Clear all expenses")
print("5. Exit")基础知识中的所有课
自己练习: Python 在线编译器