Advertisement
Guest User

3. Need for Speed III

a guest
Apr 10th, 2020
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. number_of_cars = int(input())
  2.  
  3. cars = {}
  4.  
  5. for num in range(number_of_cars):
  6.     car_input = input().split('|')
  7.     car = car_input[0]
  8.     mileage = int(car_input[1])
  9.     fuel = int(car_input[2])
  10.  
  11.     cars[car] = []
  12.     cars[car].append(mileage)
  13.     cars[car].append(fuel)
  14.  
  15.  
  16. args = input()
  17.  
  18. while args != 'Stop':
  19.     args = args.split(':')
  20.     command = args[0]
  21.  
  22.     if command == 'Drive':
  23.  #       print(command)
  24.         car = args[1]
  25.         distance = int(args[2])
  26.         fuel = int(args[3])
  27.  
  28.         if cars[car][1] < fuel:
  29.             print(f"Not enough fuel to make that ride")
  30.         else:
  31.             cars[car][0] += distance
  32.             cars[car][1] -= fuel
  33.             print(f"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed.")
  34.             if cars[car][0] >= 100000:
  35.                 del cars[car]
  36.                 print(f"Time to sell the {car}!")
  37.  
  38.     elif command == 'Refuel':
  39.         car = args[1]
  40.         fuel = int(args[2])
  41.  
  42.         cars[car][1] += fuel
  43.         if cars[car][1] > 75:
  44.             cars[car][1] = 75
  45.             print(f"{car} refueled with {fuel - cars[car][1]} liters")
  46.             args = input()
  47.             continue
  48.         print(f"{car} refueled with {fuel} liters")
  49.  
  50.     elif command == 'Revert':
  51.         car = args[1]
  52.         kilometers = int(args[2])
  53.  
  54.         cars[car][0] -= kilometers
  55.         if cars[car][0] < 10000:
  56.             cars[car][0] = 10000
  57.             args = input()
  58.             continue
  59.         print(f"{car} mileage decreased by {kilometers} kilometers")
  60.  
  61.  
  62.     args = input()
  63.  
  64. for car, value in sorted(cars.items(), key=lambda v: (-v[1][0], v[0])):
  65.     print(f"{car} -> Mileage: {value[0]} kms, Fuel in the tank: {value[1]} lt.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement