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
10 Respostas
+ 5
#simple
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
key= input()
print(car[key])
+ 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')
+ 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
+ 1
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
key=input()
if key in car :
print(car.get(key))
0
print(car['brand'])
you can call it from dictionary using its key
0
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
key= input()
print(car[key])
0
car = {
'brand': 'BMW',
'year': 2018,
'color': 'red'
}
data = input("Enter the key: ")
print(car[data])
0
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
key= input()
print(car[key])
0
#simple
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
key= input()
print(car[key])
0
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
key = input("Enter the key: ")
print(car[key])