0
Consider bears = {"Grizzly":"angry", "Brown":"friendly", "Polar":"friendly"}. Can you replace #blank#
Consider bears = {"Grizzly":"angry", "Brown":"friendly", "Polar":"friendly"}. Can you replace #blank# so the code will print a greeting only to friendly bears? Your code should work even if more bears are added to the dictionary. for bear in bears: if #blank#: print("Hello, "+bear+" bear!") else: print("odd")
7 Answers
+ 8
This looks like an assignment, so I'll only give you some hints.
Do you know how to get the value corresponding to a key in a dictionary? If not this lesson might help you:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2450/?ref=app
Now here bears is the dictionary, and by using "for bear in bears:", we make the variable bear iterate over the keys of the dictionary. All you have to do is check if the value corresponding to a key equals "friendly".
Does that make sense? Hope you can solve it now :)
+ 4
You're close, but bears.values is incorrect. As bear iterates over the keys of the dictionary, we need to access the value from the dictionary for that specific key. It's all there in the lesson!
0
answer any one
0
i tried
if bears.values=="friendly":
printing only odd
0
bears[bear]=="friendly"
0
what's answer
0
if(bears[bear] == "friendly"):