-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpenses_tracker.py
More file actions
67 lines (56 loc) · 2.4 KB
/
Expenses_tracker.py
File metadata and controls
67 lines (56 loc) · 2.4 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#mini project: Expense Tracker
#Question/problem statement: create a console-based expense tracker program in python that allows the user to record daily expenses abd view summaries like total spending. use only the concepts learned till chapter6(loop,copnditions,lists,dictionaries,basic input/output).
#project details/ description:
#you are requied to build a simple personal finance management tool.
#the program should allow the user to:
#1.add an expense with details like date,category,description,and amount.
#2.view all recorded expenses.
#3.calculate total spending so far.
#4.exit the program gracefully when the user chooses to.
#all tasks must be implemented using loops,if-else,lists,and dictuonaries on;ly.no user-defined function or file handling should be used.
expenses=[ ] #list of expenses in form of dictionaries
print("Welcome to the Expense Tracker!")
while True:
print("=====MENU=====")
print("1. Add Expense")
print("2. View All Expenses")
print("3. View Total Spending")
print("4. Exit")
choice=int(input("Enter your choice(1-4): "))
#Add Expense
if(choice==1):
date=input("Enter the date(yyyy-mm-dd):")
category=input("Enter the category(food,transportation,utilities,etc):")
description=input("Enter a brief description of the expense:")
amount=float(input("Enter the amount spent:"))
expense={
"Date":date,
"Category":category,
"Description":description,
"Amount":amount
}
expenses.append(expense)
print("Expense added successfully!")
#View All Expenses
elif(choice==2):
if len(expenses)==0:
print("No expenses recorded yet.")
else:
print("Recorded Expenses:")
count=1
for expense in expenses:
print(f"Expense {count} -> Date: {expense['Date']}, Category: {expense['Category']}, Description: {expense['Description']}, Amount: ${expense['Amount']}")
count += 1
#View Total Spending
elif(choice==3):
total_spending=0
for expense in expenses:
total_spending += expense['Amount']
print(f"Total Spending so far: ${total_spending}")
#Exit
elif(choice==4):
print("Exiting the Expense Tracker. Goodbye!")
break
#if user enters invalid choice
else:
print("Invalid choice. Please enter a number between 1 and 4.")