Dictionary | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
- 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 Respostas
+ 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