Shopping at the Market please help me!


#1

groceries = ["banana: 7", "orange: 3", "apple: 1"]
for key in groceries:
print key

Please help me !!!


#2

groceries = {
"banana": 5,
"orange": 3,
"apple": 1,
}

for key in groceries:
print "groceries: %s" % groceries[key]

Oops, try again. It looks like groceries is not a list.


#3

^ is a dictionary, this is a list:

aList = ["item1","item2","item3"]

#4

groceries = ["banana: 5","orange: 3","apple: 1"]

for key in groceries:
print groceries

Oops, try again. It looks like "banana" is not in your list


#5

You must create a dictionary, not a list in this exercise. You must have an intended block in your for loop. The value of keys in a dictionary must not be in quotes. It should be outside the quotes.

The correct way to code will be like this:

prices = {"banana": 4, "apple": 2, "orange": 1.5, "pear": 3}

This worked for me and the loop will be like this:

for key in prices:
    print key
    print "price: %s" % prices[key]

#6

thanks for everythink


#7

so the question was not related to this exercise? that is a misleading title


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.