Create an empty dictionary called Car_0 . Then fill the dictionary with Keys : color , speed , X_position and Y_position.
car_0 = {'x_position': 10, 'y_position': 72, 'speed': 'medium'} .
a) If the speed is slow the coordinates of the X_pos get incremented by 2.
b) If the speed is Medium the coordinates of the X_pos gets incremented by 9
c) Now if the speed is Fast the coordinates of the X_pos gets incremented by 22.
Print the modified dictionary.
Car_0 = {}
Car_0['x_position'] = 10
Car_0['y_position'] = 72
Car_0['speed'] = 'medium'
Car_0['color'] = 'red'
if Car_0['speed'] == 'slow':
  Car_0['x_position'] += 2
elif Car_0['speed'] == 'medium':
  Car_0['x_position'] += 9
elif Car_0['speed'] == 'fast':
  Car_0['x_position'] += 22
print(Car_0)
Comments
Leave a comment