Budget Calculator in Python Homework Sample

Lena needs a program to simulate her budget, she gets between $1,500 and $2,000 each month. Allow her to enter her rent, and expenses for the upcoming month. Check if she is able to pay everything, without having to ask for a loan from the bank of Mom and Dad. Allow the program to repeat until she decides to stop. Write a program that reads in a file and displays it, it should handle all the exceptions that are likely to happen (such as no file present with that name, some problem reading the file, etc). For more Python programming assignments contact us for a quote.

Solution:

budget.py

import pandas as pd
import random

while True:
budget = round(random.uniform(1500, 2000), 2)

rent = float(input(“a. Enter the next month’s house rent($) : “))
others = float(input(“b. Enter other expenses in the next month($) : “))

total_expense = rent + others

print(“\nLina’s total budget for the next month is: ${}”.format(budget))
print(“Lina’s total expense for the next month is: ${}”.format(total_expense))

if total_expense > budget:
print(“Will Lina be within her budget, over her budget or matches the budget?: Over her Budget!”)
elif total_expense < budget:
print(“Will Lina be within her budget, over her budget or matches the budget?: Within the Budget!”)
else:
print(“Will Lina be within her budget, over her budget or matches the budget?: Matches the Budget!”)

choice = input(‘\nContinue?’)
if choice not in [“Yes”, “Y”, “yes”]:
break

file.py

filename = str(input(“Enter the file name: “))

try:
with open(filename, ‘r’) as f:
for line in f.readlines():
print(line)

except FileNotFoundError:
print(“The file does not exist”)

except PermissionError:
print(“You don’t have the permission to open the file”)

except (IOError, OSError):
print(“You have encountered a system error”)

except Exception:
print(“Unexpected error occured”)