In: Computer Science
print('Barnabas Harris')
# Define showExspenses function
def showExpenses(loan, insure, gas, oil, tyres, maintenance):
expense = loan + insure + gas + oil + tyres + maintenance
# Print monthly and yearly automobile operating expenses
print("\nTotal Monthly expenses for operating expenses you entered
= ", expense)
print(f"\nTotal Yearly expenses for operating expenses you entered
= 12 *", expense,
f"= {expense * 12:,}") # yearly expenses
# write the testing code inside main function
def main():
loan = int(input("Enter Loan :"))
insure = int(input("Enter Insurance :"))
gas = int(input("Enter Gas :"))
oil = int(input("Enter Oil :"))
tyres = int(input("Enter Tyres :"))
maintenance = int(input("Enter Maintenance:"))
showExpenses(loan, insure, gas, oil, tyres, maintenance)
# call the main function here
main()
I am a student using python programming.
My goal for this program is to
1. format the monthly and yearly output with $ sign
2. format the monthly and yearly output with two decimal places like $ 877.00 and $ 10, 524
Things I tried.
# Define showExspenses function
def showExpenses(loan, insure, gas, oil, tyres, maintenance):
expense = loan + insure + gas + oil + tyres + maintenance
expense = round(expense, 2)
# Print monthly and yearly automobile operating expenses
print("\nTotal Monthly expenses for operating expenses you entered
= ", "$" +str(expense))
print(f"\nTotal Yearly expenses for operating expenses you entered
= 12 *", expense,
f"= {expense * 12:,}") # yearly expenses
# write the testing code inside main function
def main():
loan = float(input("Enter Loan: "))
insure = float(input("Enter Insurance : "))
gas = int(input("Enter Gas: "))
oil = int(input("Enter Oil: "))
tyres = int(input("Enter Tyres: "))
maintenance = int(input("Enter Maintenance: "))
showExpenses(loan, insure, gas, oil, tyres, maintenance)
# call the main function here
main()
This gives me
Enter Loan: 465
Enter Insurance : 150
Enter Gas: 215
Enter Oil: 25
Enter Tyres: 10
Enter Maintenance: 12
Total Monthly expenses for operating expenses you entered = $877.0
Total Yearly expenses for operating expenses you entered = 12 * 877.0 = 10,524.0
My yearly output should be $ 10,524.00 and my monthly should be $ 877.00
print('Barnabas Harris')
# Define showExspenses function
def showExpenses(loan, insure, gas, oil, tyres, maintenance):
expense = loan + insure + gas + oil + tyres + maintenance
# Print monthly and yearly automobile operating expenses
expense =(float(expense))
print("\nTotal Monthly expenses for operating expenses you entered
= ","$"+ "{:.2f}".format(expense))
print(f"\nTotal Yearly expenses for operating expenses you entered
= 12 *", expense,f"= ${expense * 12:,}"+"0")
# write the testing code inside main function
def main():
loan = int(input("Enter Loan :"))
insure = int(input("Enter Insurance :"))
gas = int(input("Enter Gas :"))
oil = int(input("Enter Oil :"))
tyres = int(input("Enter Tyres :"))
maintenance = int(input("Enter Maintenance:"))
showExpenses(loan, insure, gas, oil, tyres, maintenance)
# call the main function here
main()
Screenshots:
The screenshots are attached below for reference.
Please follow them for output and proper indentation.