4

I get the "TypeError: 'NoneType' object is not iterable" on the line "companyName, monthAverage, costPerTon, totalCost = displayCost(companyName, monthAverage, costPerTon, totalCost)" and I can't for the life of me figure out why.

Sorry I can't seem to get it to format correctly...

4-25-11 Final Project, Global Garbage Program

the main function

def main():

    #intialize variables
    endProgram = 'no'
    companyName = 'NONAME'

    #call to input company name
    companyName = inputName(companyName)

    #start 'end program' while loop
    while endProgram == 'no':

        #initializes variables
        companyName = 'NONAME'
        monthAverage = 0
        costPerTon = 0
        totalCost = 0
        yearTotal = 0

        #call to input company name
        companyName = inputName(companyName)

        #call to get the tonnage
        yearTotal, monthAverage = getTonnage(yearTotal, monthAverage)

        #call to calculate the cost
        monthAverage, costPerTon, totalCost, yearTotal = calculateCost(monthAverage, costPerTon, totalCost, yearTotal)

        #call to display the cost
        companyName, monthAverage, costPerTon, totalCost = displayCost(companyName, monthAverage, costPerTon, totalCost)

        endProgram = raw_input('Do you want to end the program? (enter yes or no)')

gets the company name

def inputName(companyName):
    companyName = raw_input('What is the name of your company? ')
    return companyName

gets the tonnage

def getTonnage(yearTotal, monthAverage):
    yearTotal = input('How many tons of garbage are you dumping this year? ')
    monthAverage = yearTotal / 12
    return yearTotal, monthAverage

calculates the call

def calculateCost(monthAverage, costPerTon, totalCost, yearTotal):
    if monthAverage > 100:
        costPerTon = 7000
    elif monthAverage > 50:
        costPerTon = 6500
    elif monthAverage > 20:
        costPerTon = 5500
    else:
        costPerTon = 4500
    totalCost = costPerTon * yearTotal
    return monthAverage, costPerTon, totalCost, yearTotal

prints the cost

def displayCost(companyName, monthAverage, costPerTon, totalCost):
    print 'Dear',companyName
    print 'The average tonnage per month is ', monthAverage
    print 'The cost per ton is $',costPerTon
    print 'The total the is the cost per ton times total tons $',totalCost

runs main

main()

2 Answers 2

6

You try to unpack the return value of displayCost into 4 variables, but displayCost doesn't return anything. Because every function call returns something in Python (or throws an exception), None is returned. Then None can't be unpacked.

You probably want to change:

companyName, monthAverage, costPerTon, totalCost = displayCost(companyName, monthAverage, costPerTon, totalCost)

To:

displayCost(companyName, monthAverage, costPerTon, totalCost)
Sign up to request clarification or add additional context in comments.

Comments

3

displayCost() doesn't return anything.

>>> a, b, c = None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.