0

Hi, i think I'm missing something, can any one tell what I'm doing wrong?

I'm doing this test task Dictionaries can be indexed as lists, using square brackets. Fill in the code provided to output the number of apples present in the store. store = {"Orange": 2, "Watermelon": 0, "Apple": 8, "Banana": 42} I did this code that does what the test task ask me to do: D = input () if D == "Orange": print (store ["Orange"]) elif D == "Watermelon": print (store ["Watermelon"]) elif D == "Apple": print (store ["Apple"]) elif D == "Banana": print (store ["Banana"]) For some reason that I don't know, when I'm using this code in the test task code play ground it doesn't work, but in the normal code play ground it works. I don't know if I'm missing something, if anyone one know how to fix it I'll appreciate it.

11th Aug 2021, 8:08 PM
Alan Restrepo
Alan Restrepo - avatar
13 odpowiedzi
+ 2
anthony silver looking at your code, it will run and produce the requested output if you enter Apple. But you may have an indentation error. Python is very picky about this. I ran your code with proper indentation and it works fine
11th Aug 2021, 8:45 PM
Paul K Sadler
Paul K Sadler - avatar
+ 2
Sounds like a case of a missing dictionary definition to me. Did you copy paste this from the original problem into your code playground? Because if you did, you might've forgotten to add the actual dictionary definition, which would cause problems because you wouldn't be able to access any of the elements inside "store". Indentation may also be a problem, but copy paste isn't too accurate when it comes to whitespace in discussion posts, but I can't be for sure.
11th Aug 2021, 10:38 PM
BootInk
BootInk - avatar
+ 1
BootInk , hi, the only thing that I copy paste is : Store={"Orange":2 "Watermelon":0, "Apple":8, "Banana":42} The rest of the code i made it my self
11th Aug 2021, 10:45 PM
Alan Restrepo
Alan Restrepo - avatar
+ 1
hmmm, seems like you may not be giving it any input (if you're testing it out in code playground rather than the task prompt). If that's the case, it won't have an output, because you don't have an else case that prints out "no output" for reference. Though if it's in the actual task prompt, then I'm out of ideas, and can only surmise that it's a problem with the question if it's not giving any input automatically.
11th Aug 2021, 11:01 PM
BootInk
BootInk - avatar
+ 1
BootInk thanks for the help man
11th Aug 2021, 11:10 PM
Alan Restrepo
Alan Restrepo - avatar
0
anthony silver Create your dictionary store ={"apple" : 2, "orange" : 5, } d = input() print(store[d]) The square brackets use your input variable to produce the result from your dictionary
11th Aug 2021, 8:37 PM
Rik Wittkopp
Rik Wittkopp - avatar
0
BootInk That dictionary was given to me by the same test task
11th Aug 2021, 10:46 PM
Alan Restrepo
Alan Restrepo - avatar
0
BootInk The problem is in the code play ground of the test task it tells me " no input" and " no out put"
11th Aug 2021, 10:53 PM
Alan Restrepo
Alan Restrepo - avatar
0
BootInk but in the normal code play ground it works fine
11th Aug 2021, 10:53 PM
Alan Restrepo
Alan Restrepo - avatar
0
BootInk don't know
11th Aug 2021, 10:54 PM
Alan Restrepo
Alan Restrepo - avatar
0
Why?
11th Aug 2021, 10:54 PM
Alan Restrepo
Alan Restrepo - avatar
0
BootInk i think the same, i thought for an input the program need that the user put the information and then print what the task tell me but I tried and it still tell me "no input" "no "no out put" but in the normal code play ground it wor
11th Aug 2021, 11:10 PM
Alan Restrepo
Alan Restrepo - avatar
0
anthony silver what lesson is that in or is that a code coach problem? I don't have pro, so if it's pro I won't be able to look at it. But if not I will take a peek.
11th Aug 2021, 11:26 PM
Paul K Sadler
Paul K Sadler - avatar