Why your tutorial dont accept my "correct" answer?


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/fr/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/keeping-track-of-the-produce-?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>

My code is correct …

<What do you expect to happen instead?>

all happens has expected …


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

stock = {
  "banana": 6,
  "apple": 0,
  "orange": 32,
  "pear": 15
}

count = 0 # the counter for keys index

for le_fruit in stock:
  print stock.keys()[count] # i want display the fruit's name
  print "price: %s" % prices[le_fruit]
  print "stock: %s" % stock[le_fruit]
  print "" # a space beetween 2 entry of stock info
  count +=1




#2

look at the loop:

for le_fruit in stock:

python will assign the keys (banana, apple and so on) of dictionary to the loop iterator (le_fruit), so if you want to print the fruits name, you can simply print le_fruit

given the loop also handles the assigning of keys to the loop iterator, you don’t need count = 0 and count += 1

i am afraid you can’t do that, given the exercise validates that there only 3 print statements, doing print "" includes a 4th print statement

if you really want to do this, see if you can use a new line character (\n), if you know how to, otherwise leave it for now


#3

I am convinced i tested “Print le_fruit” as the first try … why i would do more complicated ?

Just maybe i rewrite wrongly and i miss the mistake (ex" Le_fruit" instead of “le_fruit” or something like) and I tried other things …

so its ok it work now :

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

stock = {
  "banana": 6,
  "apple": 0,
  "orange": 32,
  "pear": 15
}

#count = 0

for le_fruit in stock:
  
  #pTTTrint stock.keys()[count] # i want display the fruit's name
  
  print le_fruit
  print "price: %s" % prices[le_fruit]
  print "stock: %s" % stock[le_fruit]
  
  #pTTTrint ""
  #count +=1

The Red message " You should have exactly three print statements! (Make sure there are no occurrences of ‘print’ in any comment or string!) " helped me : i TTT the print who was in comments …


#4

not sure why you would do something more complicated

its recommended to have variable names in all lowercase, if the variable name consist of multiply words, to use underscores.


#5

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