Dictionary | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

Dictionary

You are working at a car dealership and store the car data in a dictionary: car = { 'brand': 'BMW', 'year': 2018, 'color': 'red' } Your program needs to take the key as input and output the corresponding value. Sample Input: year Sample Output: 2018

19th Mar 2021, 6:29 AM
Kathiravan P
Kathiravan P - avatar
10 Answers
+ 5
#simple car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key= input() print(car[key])
5th Apr 2021, 5:53 AM
Allan 🔥STORMER🔥🔥🔥🔥
Allan 🔥STORMER🔥🔥🔥🔥 - avatar
+ 1
Take an input which should match the key and then call the get() on the dictionary by passing that key. Eg- car.get('year')
19th Mar 2021, 6:47 AM
Avinesh
Avinesh - avatar
+ 1
Your program needs to take the key as input and output the corresponding value. (#① 需要 将 key作为(=) input()输入函数 的 变量, #② 然后将字典 car 和 变量key ,打印 出相应的值。) car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key= input() #① print(car[key]) #② tq Allan QBit
5th Apr 2021, 11:04 PM
LEE KWANG PHENG
LEE KWANG PHENG - avatar
+ 1
car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key=input() if key in car : print(car.get(key))
25th Jul 2021, 3:41 PM
Asbibi
Asbibi - avatar
0
print(car['brand']) you can call it from dictionary using its key
30th Mar 2021, 4:44 PM
mohamad bilal
mohamad bilal - avatar
0
car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key= input() print(car[key])
9th Apr 2021, 12:49 PM
Anas Emad
0
car = { 'brand': 'BMW', 'year': 2018, 'color': 'red' } data = input("Enter the key: ") print(car[data])
22nd Nov 2021, 7:50 PM
Mohammad Jamal Mahmoud Al Jadallah
Mohammad Jamal Mahmoud Al Jadallah - avatar
0
car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key= input() print(car[key])
29th Nov 2021, 3:48 PM
Danish Al Muqri
0
#simple car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key= input() print(car[key])
16th Dec 2021, 5:36 AM
Md. Rakibul Islam
Md. Rakibul Islam - avatar
0
car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } key = input("Enter the key: ") print(car[key])
5th Oct 2023, 1:55 PM
Elham Mohammad