Advertisement
go6odn28

need_for_speed_III

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