1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Software Development' started by LagunaGTO, Oct 31, 2011.

Thread Status:
Not open for further replies.
  1. LagunaGTO

    LagunaGTO Account Closed Thread Starter

    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
     
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 733,556 other people just like you!

Loading...
Similar Threads - Python TypeError 'float'
  1. paul52104
    Replies:
    0
    Views:
    178
  2. 3251kapil
    Replies:
    1
    Views:
    913
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1024823

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice