Automobile Costs
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.
Automobile Costs Python code:
#The 'getExpenseInput' is used to asks the user
#to enter the monthly costs for loan payment,
#insurance, gas, oil, tires, and maintenance
def getExpenseInput():
amount = []
amount.append(float(input("Enter monthly loan payment: ")))
amount.append(float(input("Enter monthly insurance cost: ")))
amount.append(float(input("Enter monthly gas cost: ")))
amount.append(float(input("Enter monthly oil cost: ")))
amount.append(float(input("Enter monthly tires cost: ")))
amount.append(float(input("Enter monthly maintenance cost: ")))
return amount
#The 'computeExpenseTotal' is used to the
#total monthly cost of these expenses, and
#the total annual cost of these expenses
def computeExpenseTotal(expenses):
monthlyTotal = sum(expenses)
annualTotal = monthlyTotal * 12
return monthlyTotal, annualTotal
#main method
def main():
#Call the methods and display output
expenses = getExpenseInput()
monthlyCost, annualCost = computeExpenseTotal(expenses)
print("Total monthly cost: $", format(monthlyCost, ".2f"))
print("Total annual cost: $", format(annualCost, ".2f"))
if __name__ == "__main__":
main()
Executed Output:
Enter monthly loan payment: 21000
Enter monthly insurance cost: 5500
Enter monthly gas cost: 1200
Enter monthly oil cost: 2000
Enter monthly tires cost: 500
Enter monthly maintenance cost: 20000
Total monthly cost: $ 50200.00
Total annual cost: $ 602400.00