Advertisement
DiYane

Trains

Sep 20th, 2023
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. num_wagons = int(input())
  2.  
  3. train = [0] * num_wagons
  4.  
  5. while True:
  6.     command = input()
  7.     if command == "End":
  8.         break
  9.  
  10.     parts = command.split()
  11.     action = parts[0]
  12.  
  13.     if action == "add":
  14.         people = int(parts[1])
  15.         train[-1] += people
  16.  
  17.     elif action == "insert":
  18.         index = int(parts[1])
  19.         people = int(parts[2])
  20.         train[index] += people
  21.  
  22.     elif action == "leave":
  23.         index = int(parts[1])
  24.         people = int(parts[2])
  25.         train[index] -= people
  26.  
  27. print(train)
  28.  
  29.  
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement