Advertisement
viligen

need_for_speed

Nov 28th, 2021
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. n = int(input())
  2.  
  3. cars = {}
  4. for _ in range(n):
  5.     car, mileage, fuel = input().split("|")
  6.     cars[car] = {"mileage": int(mileage), "fuel": int(fuel)}
  7.  
  8. while True:
  9.     command = input().split(" : ")
  10.     if command[0] == "Stop":
  11.         break
  12.     car = command[1]
  13.     if command[0] == "Drive":
  14.         distance, fuel = int(command[2]), int(command[3])
  15.         if cars[car]["fuel"] < fuel:
  16.             print("Not enough fuel to make that ride")
  17.         else:
  18.             cars[car]["fuel"] -= fuel
  19.             cars[car]["mileage"] += distance
  20.             print(f"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed.")
  21.             if cars[car]["mileage"] >= 100_000:
  22.                 print(f"Time to sell the {car}!")
  23.                 del cars[car]
  24.  
  25.     elif command[0] == "Refuel":
  26.         fuel = int(command[2])
  27.         if cars[car]["fuel"] + fuel > 75:
  28.             fuel = 75 - cars[car]["fuel"]
  29.         cars[car]["fuel"] += fuel
  30.         print(f"{car} refueled with {fuel} liters")
  31.     elif command[0] == "Revert":
  32.         kilometers = int(command[2])
  33.         if cars[car]["mileage"] - kilometers < 10_000:
  34.             cars[car]["mileage"] = 10_000
  35.         else:
  36.             cars[car]["mileage"] -= kilometers
  37.             print(f"{car} mileage decreased by {kilometers} kilometers")
  38.  
  39. sorted_cars = sorted(cars.items(), key=lambda kvp: (-kvp[1]["mileage"], kvp[0]))
  40.  
  41. for car_, data in sorted_cars:
  42.     print(f"{car_} -> Mileage: {data['mileage']} kms, Fuel in the tank: {data['fuel']} lt.")
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement