-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersonalExpensePredictionAssistant.py
77 lines (63 loc) · 2.65 KB
/
PersonalExpensePredictionAssistant.py
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
68
69
70
71
72
73
74
75
76
77
def get_user_inputs():
"""Collects user inputs for income and expenses."""
print("Welcome to the Personal Expense Prediction Assistant!\n")
try:
income = float(input("Enter your total monthly income: "))
print("\nNow, enter your monthly expenses for the following categories:")
rent = float(input("Rent: "))
groceries = float(input("Groceries: "))
utilities = float(input("Utilities (electricity, water, etc.): "))
entertainment = float(input("Entertainment: "))
others = float(input("Other expenses: "))
return {
"income": income,
"expenses": {
"Rent": rent,
"Groceries": groceries,
"Utilities": utilities,
"Entertainment": entertainment,
"Others": others
}
}
except ValueError:
print("Invalid input. Please enter numeric values only.")
return None
def calculate_expenses(data):
"""Calculates total expenses and provides suggestions."""
total_expenses = sum(data['expenses'].values())
remaining_income = data['income'] - total_expenses
suggestions = []
if remaining_income < 0:
suggestions.append("You are overspending. Consider reducing your expenses.")
elif remaining_income < data['income'] * 0.2:
suggestions.append("Your savings are low. Try to save at least 20% of your income.")
else:
suggestions.append("You have a healthy balance. Keep up the good financial habits!")
return {
"total_expenses": total_expenses,
"remaining_income": remaining_income,
"suggestions": suggestions
}
def display_summary(data, results):
"""Displays a summary of expenses and predictions."""
print("\n===== Expense Summary =====")
print(f"Monthly Income: ${data['income']:.2f}")
print("\nExpenses Breakdown:")
for category, amount in data['expenses'].items():
print(f" {category}: ${amount:.2f}")
print(f"\nTotal Expenses: ${results['total_expenses']:.2f}")
print(f"Remaining Income: ${results['remaining_income']:.2f}")
print("\nSuggestions:")
for suggestion in results['suggestions']:
print(f" - {suggestion}")
def main():
"""Main function to run the Personal Expense Prediction Assistant."""
print("===== Personal Expense Prediction Assistant =====")
user_data = get_user_inputs()
if user_data:
results = calculate_expenses(user_data)
display_summary(user_data, results)
else:
print("Could not analyze expenses due to invalid input.")
if __name__ == "__main__":
main()