- 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 Antworten
+ 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])