Hello,

i'm very new to programming in genera. Python is the first language I'm learning.

So,

I was instructed to make a program that ask the user for loan payment, insurance, gas, oil, tires, and maintenance. The program will calculate the monthly cost and annual cost.

here is what i have so far..

def expenses():
    loanpayment = input ("Enter The amount of the loan payment")
    insurance = input ("Enter the amount of teh incurance")
    gas = input ("Enter the amount of the gas expenses")
    oil = input ("Enter the amount of the oil change service")
    tires = input ("Enter the amount to replace the tiresa")
    maintenance = input ("Enter the amout for maintenance")
    return expenses

i need to use module to create the program, so a module to calculate the monthly expenses and another model to calculate the annual expenses.

So my question is how do i add every that was inputed from the user?
that way i can create a module that use the total * 12 for the annual expenses..

Thank for the help

Are you sure you want to return the function as value of the same function?

the reason i'm returning is because i'm calling that whole function later on

update on the code

#Getting input from the user of the expenses
def expenses():
    loanpayment = input ("Enter The amount of the loan payment")
    insurance = input ("Enter the amount of teh incurance")
    gas = input ("Enter the amount of the gas expenses")
    oil = input ("Enter the amount of the oil change service")
    tires = input ("Enter the amount to replace the tiresa")
    maintenance = input ("Enter the amout for maintenance")
    sum = loanpayment + insurance + gas + oil + tires + maintenance
    print 'Your monthly expenses are', sum
    return expenses

def annual():
    annual = expenses() * 12.0
    return annual
    

#calling main fuctions
def main():
    print 'This program will calculate your monthly and annual car expenses'
    print annual() 
    
main()

that what i have.. but i'm getting a error

so what i'm trying to do is a function that uses the total from the monthly expenses * 12 to get annual and display monthly and annual.. where is my mistake?

Edited 6 Years Ago by pixelss: n/a

To do minimal edits and keep your style (which is little special):

#Getting input from the user of the expenses
def expenses():
    loanpayment = input ("Enter The amount of the loan payment")
    insurance = input ("Enter the amount of teh incurance")
    gas = input ("Enter the amount of the gas expenses")
    oil = input ("Enter the amount of the oil change service")
    tires = input ("Enter the amount to replace the tiresa")
    maintenance = input ("Enter the amout for maintenance")
    sum_ = loanpayment + insurance + gas + oil + tires + maintenance # sum is built in function
    print 'Your monthly expenses are', sum_
    return sum_

def annual():
    annual = expenses() * 12.0
    return annual
    

#calling main fuctions
def main():
    print 'This program will calculate your monthly and annual car expenses'
    print annual(), 'annually'
    
main()

Maybe you should learn to deal with exceptions also (user not giving proper input)?

Edited 6 Years Ago by pyTony: n/a

tonyjv: thank you, that work good, but 'annually is not showing up" just the total from the calculation from the sum * 12

thats what i'm doing right now, reading about 'if statement and exceptions'.

I'm trying to implement the exception of letters, that way if the user try to use a letter it will not crash the program...

Edited 6 Years Ago by pixelss: n/a

This article has been dead for over six months. Start a new discussion instead.