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")

12th Dec 2018, 5:31 PM
Ponugoti Sravan Kumar Reddy
Ponugoti Sravan Kumar Reddy - avatar
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 :)
12th Dec 2018, 5:44 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 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!
12th Dec 2018, 6:22 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
answer any one
12th Dec 2018, 5:36 PM
Ponugoti Sravan Kumar Reddy
Ponugoti Sravan Kumar Reddy - avatar
0
i tried if bears.values=="friendly": printing only odd
12th Dec 2018, 6:00 PM
Ponugoti Sravan Kumar Reddy
Ponugoti Sravan Kumar Reddy - avatar
0
bears[bear]=="friendly"
22nd Mar 2020, 1:30 PM
PRANAV KAKADIYA
PRANAV KAKADIYA - avatar
0
what's answer
12th Jul 2020, 10:24 AM
si va
si va - avatar
0
if(bears[bear] == "friendly"):
22nd Jul 2020, 10:11 PM
Shahnawaz Ali
Shahnawaz Ali - avatar