Good 'ol Python - TypeError: 'float' object is not iterable

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

LagunaGTO

Thread Starter
Account Closed
Joined
Jan 27, 2011
Messages
139
I am getting a TypeError: 'float' object is not iterable error in my Python coding.

I am trying to collect data from gas receipts but I want all of it under 1 function as I do not want it to keep asking "how many receipts do you have?" - I want it to ask that one time and then ask you all the data for each receipt. The problem is that I am establishing multiple variables under one function and something is off.

Code:
#the main function
def main():
    milesObtained = getMiles() #call to get the miles obtained
    totalPrice, totalGallons = getInput() #calls to collect total prices paid
#   totalGallons = getGallons() #calls to collect total gallons filled
    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()

Code:
Enter the starting miles: 10500
Enter the ending miles: 10700
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 39, 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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top