Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

activity 3 5 1 dictionary basics jump to level 1 dictionary food_quanti…

Question

activity 3 5 1 dictionary basics jump to level 1 dictionary food_quantity_pairs contains two key - value pairs, each representing a food name and the quantity ordered. output the quantity corresponding to key_name. click here for example 1 food_quantity_pairs = {\peaches\: 52, \milkshakes\: 29} 2 3 key_name = input() 4 5 print(key_name, \is:\) 6 7 \\\ your code goes here \\\ 8 i

Explanation:

Step1: Access dict value via key

<Expression>quantity = food_quantity_pairs[key_name]</Expression>

Step2: Print the required output

<Expression>print(key_name, "is:", quantity)</Expression>

Answer:

food_quantity_pairs = {"peaches": 52, "milkshakes": 29}
key_name = input()
print(key_name, "is:")
quantity = food_quantity_pairs[key_name]
print(quantity)

Or combined in one print statement for the final line:

food_quantity_pairs = {"peaches": 52, "milkshakes": 29}
key_name = input()
print(key_name, "is:", food_quantity_pairs[key_name])