fork download
  1. # ------------------------------------------------------------------------
  2. # Assignment 1: Personal Budget Tracker
  3. # Student Name & Surname: [Write your name here]
  4. # Student Number: [Write your student number here]
  5. # ------------------------------------------------------------------------
  6.  
  7. # Function to calculate the budget
  8. def calculate_budget(income, food, transport, entertainment):
  9. # Calculate total expenses
  10. total_expenses = food + transport + entertainment
  11. # Calculate savings (income - expenses)
  12. savings = income - total_expenses
  13. return total_expenses, savings
  14.  
  15. # Function to print the budget summary
  16. def print_budget_summary(income, food, transport, entertainment, total_expenses, savings):
  17. print("========== Mahloko 's Budget Summary ==========")
  18. print(f"Total Income: R{income}")
  19. print(f"Food Expenses: R{food}")
  20. print(f"Transport Expenses: R{transport}")
  21. print(f"Entertainment: R{entertainment}")
  22. print("---------------------------------------------")
  23. print(f"Total Expenses: R{total_expenses}")
  24. print(f"Savings Remaining: R{savings}")
  25. print("=============================================")
  26.  
  27. # Main program
  28. def main():
  29. # Given values
  30. income = 55000.00
  31. food = 2289.00
  32. transport = 2474.00
  33. entertainment = 1676.00
  34.  
  35. # Call the calculation function
  36. total_expenses, savings = calculate_budget(income, food, transport, entertainment)
  37.  
  38. # Call the print function
  39. print_budget_summary(income, food, transport, entertainment, total_expenses, savings)
  40.  
  41. # This line makes sure the program runs
  42. if __name__ == "__main__":
  43. main()
  44.  
Success #stdin #stdout 0.13s 14224KB
stdin
Standard input is empty
stdout
========== Mahloko 's Budget Summary ==========
Total Income:        R55000.0
Food Expenses:       R2289.0
Transport Expenses:  R2474.0
Entertainment:       R1676.0
---------------------------------------------
Total Expenses:      R6439.0
Savings Remaining:   R48561.0
=============================================