kostovhg

need for speed III

Jul 14th, 2021
833
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. nums = int(input())
  2. cars = {}
  3. for i in range(nums):
  4.     comm = input().split("|")
  5.     model = comm[0]
  6.     miles, fuel = int(comm[1]), int(comm[2])
  7.     cars.setdefault(model, [miles, fuel])
  8.  
  9. line = input()
  10. while True:
  11.     if line == "Stop":
  12.         break
  13.     args = line.split(" : ")
  14.     com = args.pop(0)
  15.     car = args.pop(0)
  16.     if com == "Drive":
  17.         dist, fuel = int(args[0]), int(args[1])
  18.         if cars[car][1] <= fuel:
  19.             print("Not enough fuel to make that ride")
  20.         else:
  21.             cars[car][0] += dist
  22.             cars[car][1] -= fuel
  23.             print(f"{car} driven for {dist} kilometers. {fuel} liters of fuel consumed.")
  24.             if cars[car][0] >= 100000:
  25.                 del cars[car]
  26.                 print(f"Time to sell the {car}!")
  27.     elif com == 'Refuel':
  28.         fuel = int(args[0])
  29.         if fuel + cars[car][1] >75:
  30.             fuel -= 75 - cars[car][1]
  31.         # else:
  32.         cars[car][1] += fuel
  33.         print(f"{car} refueled with {fuel} liters")
  34.     elif com == 'Revert':
  35.         kms = int(args.pop(0))
  36.         if cars[car][0] - kms <= 10000:
  37.             cars[car][0] = 10000
  38.         else:
  39.             cars[car][0] -= kms
  40.             print(f"{car} mileage decreased by {kms} kilometers")
  41.     line = input()
  42.  
  43. [print(f"{k} -> Mileage: {v[0]} kms, Fuel in the tank: {v[1]} lt.") for
  44.  k, v in sorted(cars.items(), key=lambda x: (-x[1][0], x[0]))]
  45.  
RAW Paste Data