In: Computer Science
In Python
write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses.
your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses.
DO NOT display the expenses inside of the calcExpenses function!!
Function main should get the expenses, call the calcExpenses function, and display the values.
The calcExpenses function should only calculate the monthly and annual expenses, return the values to the main function, and display the values from function main.
In case of any queries,please comment. I would be very happy to assist all your queries.Please give a Thumps up if you like the answer
Program
def calcExpenses(loan, insurance, gas, oil, tire,
maintenance):
#calculate monthly cost.
monthly_cost= loan + insurance + gas + oil + tire +
maintenance
annual_cost=monthly_cost*12
return monthly_cost,annual_cost
def main():
# Read data from user
loan = float(input("Enter your monthly cost of car loan payment:
"))
insurance = float(input("Enter your monthly cost of Insurance
amount: "))
gas = float(input("Enter monthly gas amount: "))
oil = float(input("Enter monthly amount spent on oil: "))
tire = float(input("Enter monthly cost of tires: "))
maintenance = float(input("Enter monthly maintenance cost:
"))
#call the calcExpenses
monthly_cost,annual_cost=calcExpenses (loan, insurance, gas, oil,
tire, maintenance)
#display the results
print("Total monthly cost: $",format(monthly_cost, ',.2f'),
sep='')
print("Total annual cost: $",format(annual_cost, ',.2f'),
sep='')
main()
Output
Enter your monthly cost of car loan payment: 1000
Enter your monthly cost of Insurance amount: 150
Enter monthly gas amount: 50
Enter monthly amount spent on oil: 100
Enter monthly cost of tires: 125
Enter monthly maintenance cost: 75
Total monthly cost: $1,500.00
Total annual cost: $18,000.00
Program Screenshot