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?
2/13/2021 6:39:38 AM
Kim Hammar-Milliner
10 Answers
New AnswerI 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.
Kim Hammar-Milliner It's 15000 not 5000 car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } print(car[input()])
Downvote if I am wrong because I am not understanding the problem but here is my approach, try this out https://code.sololearn.com/c8axlwqNJm03/?ref=app
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 ^^
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.
car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } print(car[input()])
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!