Ask Question
25 June, 12:16

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") Enter your code here.

+3
Answers (1)
  1. 25 June, 13:24
    0
    bears = {"Grizzly":"angry", "Brown":"friendly", "Polar":"friendly"}

    for bear in bears:

    if bears[bear] = = "friendly":

    print ("Hello, "+bear+" bear!")

    else:

    print ("odd")

    Explanation:

    A dictionary called bears is given. A dictionary consists of key-value pairs.

    You need to check each key-value pairs in bears and find the ones that have "friendly" as value using a for loop and if-else structure. In order to access the values of the dictionary, use the dictionary name and the key (inside the loop, the key is represented as bear variable). If a key has a value of "friendly", print the greeting. Otherwise, print "odd".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider bears = {"Grizzly":"angry", "Brown":"friendly", "Polar":"friendly"}. Can you replace #blank# so the code will print a greeting ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers