cupilot
cupilot

Reputation: 1

Python 2.7 Error - can't get past an error

I keep getting the

"too many variables to unpack"

error. Can anybody help me get this working, and possibly give me an explanation?

wings_quantity = {
    'small' : 8,
    'medium' : 14,
    'large' : 20,
    'half bucket' : 30,
    'bucket' : 65,
    }

wings_price = {
    'small' : 5.99,
    'medium' :8.50,
    'large' : 14.00,
    'half bucket' :20.00,
    'bucket' : 55.00
    }

for number, key in wings_quantity:
    print "  "
    print "There are "+(str(wings_quantity[number]))+ "  wings in a "+(wings_quantity[key])+" size." 
    print " "

for number, key in wings_quantity:
    ppw = wings_quantity[number] / wings_price[number]
    print ('The cost per wing in a %s size is $') + ppw  %wing_quantity[key]

Upvotes: 0

Views: 38

Answers (1)

dstudeba
dstudeba

Reputation: 9038

You are close, but you forgot to put the iteritems() on the end of your for statements.

Change

for number, key in wings_quantity:

to

for number, key in wings_quantity.iteritems():

After that problem you need to rewrite your print statements as they are trying to access the dictionary twice. Since you already have the values you can just print them like so:

print "There are "+ key + "  wings in a "+ str(value) +" size."

I tested this in 3.4 and it worked, but in 3.x you need to change it to

for number, key in wings_quantity.items():

This produced this output for the first loop

There are bucket  wings in a 65 size.
There are small  wings in a 8 size.
There are medium  wings in a 14 size.
There are half bucket  wings in a 30 size.
There are large  wings in a 20 size.

Upvotes: 2

Related Questions