-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (32 loc) · 1.1 KB
/
Copy pathmain.py
File metadata and controls
39 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from tracker import add_record, list_records, summary
def menu():
print("\n====== 简单记账工具 ======")
print("1. 添加记录")
print("2. 查看记录")
print("3. 查看汇总")
print("4. 退出")
while True:
menu()
choice = input("请输入选项:")
if choice == "1":
amount = float(input("金额(收入正数,支出负数):"))
category = input("类别(如:餐饮/工资/购物):")
note = input("备注:")
add_record(amount, category, note)
print("记录已添加!")
elif choice == "2":
records = list_records()
print("\n===== 所有记录 =====")
for r in records:
print(f"{r['time']} | {r['category']} | {r['amount']} | {r['note']}")
elif choice == "3":
income, expense, balance = summary()
print("\n===== 汇总 =====")
print("总收入:", income)
print("总支出:", expense)
print("结余:", balance)
elif choice == "4":
print("再见!")
break
else:
print("无效选项,请重试!")