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 >>>