Advertisement
simeonshopov

Tank Collector

Jan 22nd, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. tanks = [x for x in input().split(", ")]
  2. n = int(input())
  3.  
  4. for i in range(n):
  5.     tokens = [x for x in input().split(', ')]
  6.     cmd = tokens[0]
  7.     if 'Add' in cmd:
  8.         name = tokens[1]
  9.         if name in tanks:
  10.             print('Tank is already bought')
  11.         else:
  12.             print('Tank successfully bought')
  13.             tanks.append(name)
  14.     elif 'Remove At' in cmd:
  15.         idx =  int(tokens[1])
  16.         if 0 <= idx < len(tanks):
  17.             print('Tank successfully sold')
  18.             tanks.pop(idx)
  19.         else:
  20.             print('Index out of range')
  21.     elif 'Remove' in cmd:
  22.         name = tokens[1]
  23.         if name in tanks:
  24.             print('Tank successfully sold')
  25.             tanks.remove(name)
  26.         else:
  27.             print('Tank not found')
  28.     elif 'Insert' in cmd:
  29.         idx =  int(tokens[1])
  30.         new_tank =  tokens[2]
  31.         if 0 <= idx < len(tanks):
  32.             if new_tank in tanks:
  33.                 print('Tank is already bought')
  34.             else:
  35.                 print('Tank successfully bought')
  36.                 tanks.insert(idx, new_tank)
  37.         else:
  38.             print('Index out of range')
  39.  
  40. print(', '.join(tanks))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement