- 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
6 Answers
+ 3
It's color not colour
+ 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.
0
Thanks
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.
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")
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")