Advertisement
horozov86

Need for speed 3

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