# 定义一个空的账单列表
bill_list = []
# 函数:添加账单记录
def add_bill(amount, description):
bill_list.append({'amount': amount, 'description': description})
print(f'Bill added: {description} (${amount})')
# 函数:显示所有账单记录和总金额
def show_bills():
total = 0
if not bill_list:
print('Bill list is empty.')
else:
print('Bill List:')
for bill in bill_list:
total += bill['amount']
print(f'${bill["amount"]} - {bill["description"]}')
print(f'Total amount: ${total}')
# 主程序
if __name__ == '__main__':
while True:
print('\nExpense Tracker Menu:')
print('1. Add Bill')
print('2. Show Bills')
print('3. Exit')
choice = input('Enter your choice (1-3): ')
if choice == '1':
amount = float(input('Enter amount ($): '))
description = input('Enter description: ')
add_bill(amount, description)
elif choice == '2':
show_bills()
elif choice == '3':
print('Exiting Expense Tracker.')
break
else:
print('Invalid choice. Please enter a number from 1 to 3.')