Question

In: Computer Science

print('Barnabas Harris') # Define showExspenses function def showExpenses(loan, insure, gas, oil, tyres, maintenance): expense = loan...

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

Solutions

Expert Solution

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.


Related Solutions

import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(")...
import random #the menu function def menu(list, question): for entry in list: print(1 + list.index(entry),end="") print(") " + entry) return int(input(question)) plz explain this code
A new client, an oil and gas explorer in Western Canada, is currently negotiating a loan...
A new client, an oil and gas explorer in Western Canada, is currently negotiating a loan worth $3 million to avoid defaulting on its long-term debt that is due in three months. Its latest quarterly earnings report indicate that the entity has a working capital deficiency of $500,000, while its cash balance fell to $250,000, down from $500,000 a year earlier. There is a 0.5:1 current ratio. With little expectation of improved sales, the entity plans to cut back on...
import random # define functions def rollDice(): # function returns a random number between 1 and...
import random # define functions def rollDice(): # function returns a random number between 1 and 6 def userWon(t1, t2): # function accepts player total and computer total # function returns true if player wins # function returns false if computer wins def main(): # each player rolls two Dice player = rollDice() + rollDice() computer = rollDice() + rollDice() # ask the player if they want to roll again again = int(input("Please enter 1 to roll again. Enter 2...
A monopolist providing beryllium to the oil and gas sector has the following demand function Qd...
A monopolist providing beryllium to the oil and gas sector has the following demand function Qd = 60 – P. The price and quantity demand is given in the table 3 below: Table 3 P ($) 60 55 50 45 40 35 30 25 20 15 10 5 0 Qd 0 5 10 15 20 25 30 35 40 45 50 55 60 a) From the table above, calculate the Total Revenue and Marginal revenue values. b)         Plot the demand...
# Let me define the function I use for testing.  Don't change this cell. def check_equal(x, y,...
# Let me define the function I use for testing.  Don't change this cell. def check_equal(x, y, msg=None):     if x == y:         if msg is None:             print("Success")         else:             print(msg, ": Success")     else:         if msg is None:             print("Error:")         else:             print("Error in", msg, ":")         print("    Your answer was:", x)         print("    Correct answer: ", y)     assert x == y, "%r and %r are different" % (x, y) ## Problem 1: common word pairs The goal is to find the set of consecutive word pairs in common...
Explain how liquids can be analyzed by gas chromatography. Briefly define or describe the function, in...
Explain how liquids can be analyzed by gas chromatography. Briefly define or describe the function, in gas chromatography, of the carrier gas: stationary liquid phase: solid support: If ethyl acetate and n-butyl acetate are analyzed by gas chromatography, which of these esters will generally produce a peak with the shorter retention time? What operating variables determine retention time? Explain why is it important to inject the sample quickly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT