Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- cars = {}
- for _ in range(n):
- car, mileage, fuel = input().split("|")
- cars[car] = {"mileage": int(mileage), "fuel": int(fuel)}
- while True:
- command = input().split(" : ")
- if command[0] == "Stop":
- break
- car = command[1]
- if command[0] == "Drive":
- distance, fuel = int(command[2]), int(command[3])
- if cars[car]["fuel"] < fuel:
- print("Not enough fuel to make that ride")
- else:
- cars[car]["fuel"] -= fuel
- cars[car]["mileage"] += distance
- print(f"{car} driven for {distance} kilometers. {fuel} liters of fuel consumed.")
- if cars[car]["mileage"] >= 100_000:
- print(f"Time to sell the {car}!")
- del cars[car]
- elif command[0] == "Refuel":
- fuel = int(command[2])
- if cars[car]["fuel"] + fuel > 75:
- fuel = 75 - cars[car]["fuel"]
- cars[car]["fuel"] += fuel
- print(f"{car} refueled with {fuel} liters")
- elif command[0] == "Revert":
- kilometers = int(command[2])
- if cars[car]["mileage"] - kilometers < 10_000:
- cars[car]["mileage"] = 10_000
- else:
- cars[car]["mileage"] -= kilometers
- print(f"{car} mileage decreased by {kilometers} kilometers")
- sorted_cars = sorted(cars.items(), key=lambda kvp: (-kvp[1]["mileage"], kvp[0]))
- for car_, data in sorted_cars:
- print(f"{car_} -> Mileage: {data['mileage']} kms, Fuel in the tank: {data['fuel']} lt.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement