0

I am trying to write a program that collects gas receipt information. I only want it to ask one time for how many receipts there are and then I want it go ask the loop of questions.

How do I do this? I'm guessing I can't declare multiple variables in the beginning? We did not learn much in my class, so I'm trying to go above and beyond and do a little more for our project to get the program where/how I want it.

Here is my starting off code:

#the main function
def main():
    milesObtained = getMiles() #call to get the miles obtained
    totalPrice, totalGallons = getInput() #calls to collect total prices paid
    printReport(milesObtained, totalPrice, totalGallons) #call to print the full report out
    
#collects miles obtained during the month
def getMiles():
    milesStarted = input('Enter the starting miles: ')
    milesEnded = input('Enter the ending miles: ')
    milesObtained = milesEnded - milesStarted
    return milesObtained

#collects receipt data
def getInput():
    totalPrice = 0
    totalGallons = 0
    number = input('How many receipts do you have to enter? ')
    for counter in range (0, number):
        price = input('Enter the price: ')
        gallons = input('Enter the gallon amount: ')
        totalGallons = totalGallons + gallons
        totalPrice = totalPrice + price
    return totalPrice
    return totalGallons
        
#prints out the report
def printReport(milesObtained, totalPrice, totalGallons):
    print 
    print '----------------------------'
    print 'RESULTS OF GAS THIS MONTH'
    print '----------------------------'
    print 'The miles obtained were: ', milesObtained
    print 'The total price paid this month is: ', totalPrice
    print 'The total amount of gallons this month is: ', totalGallons

#calls main
main()

When I run the code, it does this:

IDLE 1.2.2      ==== No Subprocess ====
>>> 
Enter the starting miles: 105000
Enter the ending miles: 107000
How many receipts do you have to enter? 2
Enter the price: 10.00
Enter the gallon amount: 2
Enter the price: 10.00
Enter the gallon amount: 2
Traceback (most recent call last):
  File "C:\Users\fmcgovern\Documents\School Work\Programming\ProjectTest.py", line 38, in <module>
    main()
  File "C:\Users\fmcgovern\Documents\School Work\Programming\ProjectTest.py", line 4, in main
    totalPrice, totalGallons = getInput() #calls to collect total prices paid
TypeError: 'float' object is not iterable
>>>

Edited by LagunaGTO: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by vegaseat
0

Just a a quick look. Read the comments ...

#the main function
def main():
    milesObtained = getMiles() #call to get the miles obtained
    # expect the return of one totalPrice, totalGallons tuple
    totalPrice, totalGallons = getInput() #calls to collect total prices paid
    printReport(milesObtained, totalPrice, totalGallons) #call to print the full report out
    
#collects miles obtained during the month
def getMiles():
    milesStarted = input('Enter the starting miles: ')
    milesEnded = input('Enter the ending miles: ')
    milesObtained = milesEnded - milesStarted
    return milesObtained

#collects receipt data
def getInput():
    totalPrice = 0
    totalGallons = 0
    number = input('How many receipts do you have to enter? ')
    for counter in range (0, number):
        price = input('Enter the price: ')
        gallons = input('Enter the gallon amount: ')
        totalGallons = totalGallons + gallons
        totalPrice = totalPrice + price
    # return one totalPrice, totalGallons tuple
    return totalPrice, totalGallons
        
#prints out the report
def printReport(milesObtained, totalPrice, totalGallons):
    print 
    print '----------------------------'
    print 'RESULTS OF GAS THIS MONTH'
    print '----------------------------'
    print 'The miles obtained were: ', milesObtained
    print 'The total price paid this month is: ', totalPrice
    print 'The total amount of gallons this month is: ', totalGallons

#calls main
main()
0

I'm not sure I get what you're stating in the comments? If I put what you added and remove the comments, it gives me a syntax error. If you show me what the code should be, I will be able to understand. I just don't think we've learned this much and are not going to, so my knowledge is short on coming up with the answer.

0

Can you give us the content of your error message?

totalPrice, totalGallons or (totalPrice, totalGallons) is a tuple
your function has to return that to match the function call result

Edited by vegaseat: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.