+ 1
Can some body solve this please help!
5 Answers
+ 4
car = {
'brand':'BMW',
'year': 2018,
'color': 'red',
'mileage': 15000
}
x=input()
if x == 'brand':
print("BMW")
elif x == 'year':
print(2018)
elif x == 'color':
print('red')
else:
print(15000)
+ 2
Rohit Saha
No need of if else
As car is a dictionary so you can use get function
print (car.get(input()))
+ 1
Thanks a lot NEZ for answering my question thanks đđđđ
+ 1
NEZ , why?
You have already defined a dictionary!
x=input()
print(car[x])
#thats it. No need to if elif else block.
0
Shadoff
I just corrected his code rather than using other ways.
I was going through his logic.
//
You can use AJ's code too.