# 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 taking python programming.
How can I modify my program to give two decimal places and currency format as output?
Inorder to get decimal output first you should change the input from int(input()) to float(input()) then only the result will get in to decimal.
You can get up to 2 decimals by using round function.
For currency output you can give Rs or $ before printing the attribute.
# 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()
Get Answers For Free
Most questions answered within 1 hours.