Advertisement
horozov86

Need fpr spped 3 with 2 dictionaries

Apr 1st, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. n = int(input())
  2.  
  3. car_mileage = {}
  4. car_fuel = {}
  5.  
  6. for _ in range(n):
  7.     line = input()
  8.     line_split = line.split("|")
  9.     car_brand = line_split[0]
  10.     mileage = int(line_split[1])
  11.     fuel = int(line_split[2])
  12.  
  13.     car_mileage[car_brand] = mileage
  14.     car_fuel[car_brand] = fuel
  15.  
  16. while True:
  17.     data = input()
  18.     if data == "Stop":
  19.         break
  20.     data_split = data.split(" : ")
  21.     command = data_split[0]
  22.     car_brand = data_split[1]
  23.  
  24.     if command == "Drive":
  25.         distance = int(data_split[2])
  26.         fuel = int(data_split[3])
  27.  
  28.         if car_fuel[car_brand] < fuel:
  29.             print(f"Not enough fuel to make that ride")
  30.         else:
  31.             car_mileage[car_brand] += distance
  32.             car_fuel[car_brand] -= fuel
  33.             print(f"{car_brand} driven for {distance} kilometers. {fuel} liters of fuel consumed.")
  34.         if car_mileage[car_brand] >= 100000:
  35.             del car_mileage[car_brand]
  36.             del car_fuel[car_brand]
  37.             print(f"Time to sell the {car_brand}!")
  38.  
  39.     elif command == "Refuel":
  40.         fuel = int(data_split[2])
  41.         if car_fuel[car_brand] + fuel < 75:
  42.             car_fuel[car_brand] += fuel
  43.             print(f"{car_brand} refueled with {fuel} liters")
  44.         else:
  45.             diff = 75 - car_fuel[car_brand]
  46.             car_fuel[car_brand] += (75 - car_fuel[car_brand])
  47.             print(f"{car_brand} refueled with {diff} liters")
  48.  
  49.     elif command == "Revert":
  50.         kilometers = int(data_split[2])
  51.         car_mileage[car_brand] -= kilometers
  52.         if car_mileage[car_brand] >= 10000:
  53.             print(f"{car_brand} mileage decreased by {kilometers} kilometers")
  54.         else:
  55.             car_mileage[car_brand] = 10000
  56.  
  57. for car_brand in car_mileage.keys():
  58.     mileage = car_mileage[car_brand]
  59.     fuel = car_fuel[car_brand]
  60.     print(f"{car_brand} -> Mileage: {mileage} kms, Fuel in the tank: {fuel} lt.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement