- 1

Please tell mistake, Language==Python. [Solved]

# Data car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } # Inputs and outputs a = (input()) if a==("brand"): print ("BMW") if a==("year"): print (2018) if a==("colour"): print ("red") if a==("mileage"): print (15000) # There are 4 test cases 1 of them is showing wrong, Please tell me the mistake

16th Mar 2021, 12:13 PM
Krish Rathor
Krish Rathor - avatar
6 Respuestas
+ 3
It's color not colour
16th Mar 2021, 12:21 PM
Simba
Simba - avatar
+ 2
Your code isn't dynamic. Instead of print("BMW"), you can just print access the key value from the dictionary like so: print(car['brand']) Do the same for the rest and see if that works. Hope this helps.
16th Mar 2021, 12:33 PM
Billy Noah
Billy Noah - avatar
0
Thanks
16th Mar 2021, 12:29 PM
Krish Rathor
Krish Rathor - avatar
0
Hi Billy, I tried to make my code easier not dynamic I can make it dynamic but if it is easy it is easy to explain anyone.
22nd Mar 2021, 9:41 AM
Krish Rathor
Krish Rathor - avatar
0
x = input() if x in "brand": print ("BMW") else: if x in "year": print ("2018") else: if x in "color": print ("red") else: if x in "mileage": print ("15000")
8th May 2021, 9:21 PM
Ferit ÖZTÜRK
Ferit ÖZTÜRK - avatar
0
car = { 'brand':'BMW', 'year': 2018, 'color': 'red', 'mileage': 15000 } x = input() if x in "brand": print ("BMW") elif x in "year": print("2018") elif x in "color": print("red") else: x in "mileage" print("15000")
8th May 2021, 9:30 PM
Ferit ÖZTÜRK
Ferit ÖZTÜRK - avatar