+ 1
Trying to solve car data dictionary intermediate python challenge
SoRRY ABOUT THE CAPS BUT MY DEVICE WONT TURN OFF THE CAPS HERE IS THE CODE THAT I USED user_input=input() try: car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 5000 } print(car[user_input]); except KeyError: print("There is no such car as", "'" + user_input + "'", "in the dictionary!") It PASSES ON 4 OUT 5 TEST CASES AND WHAT SHOULD I DO?
14 Answers
+ 5
I can't find the challenge but I noticed something, in the challenge, the given dictionary is
car = {
'brand': 'BMW',
'year': 2018,
'color': 'red'
}
But in your code, it has an other key "mileage".
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 5000
}
EDIT: The problem is with the value of mileage, it should be 15000 and not 5000.
+ 5
Kim Hammar-Milliner
It's 15000 not 5000
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
print(car[input()])
+ 2
it is now working . thanks.
+ 1
Kim Hammar-Milliner
does your device only won't turn off caps inside description field for non-code text?
I guess not, because normal case is used for title, tags, code and even some letters of your "blocked" case ('SoRRY', 'It')...
please do not take us for dumb ^^
+ 1
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
print(car[input()])
0
Dictionaries
You are working at a car dealership and store the car data in a dictionary:
car = {
'brand': 'BMW',
'year': 2018,
'color': 'red'
}
PY
Your program needs to take the key as input and output the corresponding value.
Sample Input:
year
Sample Output:
2018
The data is already defined in the code.
0
i tried it and the test #3 still fails
0
I wrote as below
x = input()
print(car[x])
It was successed but now I know I did not need to make x to solve it. Thank you all!
0
Passes all the tests
user_input = input()
car = {
'brand': 'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
car_value = car.get(user_input, "Key not found in the dictionary!")
print(car_value)
0
user_input = input()
car = {
'brand': 'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
print(car[user_input])
This is without fun "get"
0
Jdjdjdjd
0
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
print(car[input()])
try this
- 1
i removed mileage and rerun the test and test 3 is still failing