 # 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
6.     miles, fuel = int(comm), int(comm)
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), int(args)
18.         if cars[car] <= fuel:
19.             print("Not enough fuel to make that ride")
20.         else:
21.             cars[car] += dist
22.             cars[car] -= fuel
23.             print(f"{car} driven for {dist} kilometers. {fuel} liters of fuel consumed.")
24.             if cars[car] >= 100000:
25.                 del cars[car]
26.                 print(f"Time to sell the {car}!")
27.     elif com == 'Refuel':
28.         fuel = int(args)
29.         if fuel + cars[car] >75:
30.             fuel -= 75 - cars[car]
31.         # else:
32.         cars[car] += fuel
33.         print(f"{car} refueled with {fuel} liters")
34.     elif com == 'Revert':
35.         kms = int(args.pop(0))
36.         if cars[car] - kms <= 10000:
37.             cars[car] = 10000
38.         else:
39.             cars[car] -= kms
40.             print(f"{car} mileage decreased by {kms} kilometers")
41.     line = input()
42.
43. [print(f"{k} -> Mileage: {v} kms, Fuel in the tank: {v} lt.") for
44.  k, v in sorted(cars.items(), key=lambda x: (-x, x))]
45.
RAW Paste Data