Https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/investing-in-stock-?action=lesson_resume


#1

https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/investing-in-stock-?action=lesson_resume


#2

still having issues


#3

The instructions show that they want the output to be in the following format:

apple
price: 2
stock: 0

Look at your code and how you have the strings laid out. Do they match price: and stock:?

String Formatters with Numbers Tip

The prices and stock are numbers and not strings. Right? Looking at your string formatter, you have:

print "prices : %s" % prices[key]

prices[key] will be a number. That does not directly convert into a string data type. You have 2 choices to make:

  1. Do the conversion using str(prices[key]).
  2. Change the placeholder from %s to %d.

For the 2nd one, %d accepts a signed integer decimal and then converts it into a string for you. You can learn more about the string formatters in the Python documentation.


#4


i did that and im still facing the same issue here.


#5

this is a new error now…what’s happening …am i wrong or is there a bug in this lesson ?


#6

Hi @winston2019,

Make sure the colon ( : ) in your strings is right next to price and stock. :slight_smile:


#7


Done that…no idea where this error is from


#8

Refresh your browser and see what happens. I tested your code and it works fine.


#9

same …which of my codes did you run ?


#10

The one you just posted. Can you copy your code and paste it here in Preformatted text? Thanks :slight_smile:


#11

sure

price = {
“banana”: 4,
“apple”: 2,
“orange”: 1.5,
“pear”: 3
}

stock={
“banana”: 6,
“apple” : 0,
“orange” : 32,
“pear” : 15
}
for key in price:
print “price : %s” % str(price[key])
print “stock : %s” % str(stock[key])


#12

It’s working now …sorry


#13

It’s alright :slight_smile: I’m glad you got it working :+1:


#14

and then …it stopped:rage:


#15

Okay, well can you post your code again in Preformatted text? Or is it the same code from above.
Also, what error code/s are you getting?


#16

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