Sathvik Oop
Sathvik Oop
ipynb - Colab
#/usr/bin/env python
# coding: utf-8
# In[ ]:
class Financmanager:
def __init__(self):
self.income = 0
self.savings_goal = 0
self.budget = {}
self.expenses = []
def set_income(self):
try:
self.income = float(input("Enter your monthly income: "))
print(f"Monthly income set to ${self.income}\n")
except ValueError:
print("Invalid input! Please enter a valid number.")
def set_savings_goal(self):
try:
self.savings_goal = float(input("Enter your savings goal: "))
print(f"Savings goal set to ${self.savings_goal}\n")
except ValueError:
print("Invalid input! Please enter a valid number.")
def set_budget(self):
category = input("Enter budget category: ")
try:
amount = float(input(f"Enter budget amount for {category}: "))
self.budget[category] = amount
print(f"Budget set: {category} - ${amount}\n")
except ValueError:
print("Invalid input! Please enter a valid number.")
def add_expense(self):
category = input("Enter expense category: ")
try:
amount = float(input(f"Enter expense amount for {category}: "))
if category not in self.budget:
print(f"Warning: {category} is not in the budget!")
self.expenses.append((category, amount))
print(f"Expense added: {category} - ${amount}\n")
except ValueError:
print("Invalid input! Please enter a valid number.")
def calculate_expenses(self):
return sum(amount for _, amount in self.expenses)
def check_budget(self):
print("\nBudget Report:")
for category, amount in self.budget.items():
spent = sum(exp[1] for exp in self.expenses if exp[0] == category)
print(f" {category}: Budgeted ${amount}, Spent ${spent}, Remaining ${amount - spent}")
print()
def progress_towards_goal(self):
total_expenses = self.calculate_expenses()
savings = self.income - total_expenses
print(f"\nTotal expenses: ${total_expenses}")
print(f"Savings so far: ${savings}")
if savings >= self.savings_goal:
print("Congratulations! You've reached your savings goal!\n")
else:
print(f"You need ${self.savings_goal - savings} more to reach your goal.\n")
def show_menu(self):
print("\n--- Personalized Financial Manager ---")
print("1. Set Monthly Income")
print("2. Set Savings Goal")
print("3. Set Budget")
print("4. Add Expense")
print("5. Check Budget")
print("6. View Savings Progress")
print("7. Exit")
print("-----------------------------------------")
#Main
def main():
h i ()
https://colab.research.google.com/drive/1KijVuG_Ttk_bU6Ntzc0YmI7bfrEsR5io#printMode=true 1/3
1/3/25, 11:07 AM Untitled16.ipynb - Colab
coach = Financmanager()
while True:
coach.show_menu()
choice = input("Enter your choice: ")
print()
if choice == '1':
coach.set_income()
elif choice == '2':
coach.set_savings_goal()
elif choice == '3':
coach.set_budget()
elif choice == '4':
coach.add_expense()
elif choice == '5':
coach.check_budget()
elif choice == '6':
coach.progress_towards_goal()
elif choice == '7':
print("Exiting... Thank you for using Financial Coaching!")
break
else:
print("Invalid choice! Please select a valid option.\n")
if __name__ == "__main__":
main()
#In[ ]:
Total expenses: $0
Savings so far: $2.0
Congratulations! You've reached your savings goal!
https://colab.research.google.com/drive/1KijVuG_Ttk_bU6Ntzc0YmI7bfrEsR5io#printMode=true 2/3
1/3/25, 11:07 AM Untitled16.ipynb - Colab
1. Set Monthly Income
2. Set Savings Goal
3. Set Budget
4. Add Expense
5. Check Budget
6. View Savings Progress
7. Exit
-----------------------------------------
https://colab.research.google.com/drive/1KijVuG_Ttk_bU6Ntzc0YmI7bfrEsR5io#printMode=true 3/3