Advertisement
Guest User

Untitled

a guest
Jul 1st, 2020
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. def index_in_range(index, length):
  2.     return 0 <= index < length
  3.  
  4. owned_tanks=input().split(', ')
  5. command_count=int(input())
  6.  
  7. for i in range(command_count):
  8.     token= input().split(', ')
  9.     command= token[0]
  10.  
  11.     if command == 'Add':
  12.         tank_name = token[1]
  13.         if tank_name in owned_tanks:
  14.             print ("Tank is already bought")
  15.             continue
  16.         owned_tanks.append(tank_name)
  17.         print ("Tank successfully bought")
  18.  
  19.     elif command == 'Remove':
  20.         tank_name = token[1]
  21.         if tank_name not in owned_tanks:
  22.             print("Tank not found")
  23.             continue
  24.         owned_tanks.remove(tank_name)
  25.         print("Tank successfully sold")
  26.  
  27.     elif command == 'Remove At':
  28.         index = int(token[1])
  29.         if not index_in_range (index, len(owned_tanks)):
  30.             print("Index out of range")
  31.             continue
  32.         owned_tanks.pop(index)
  33.         print("Tank successfully sold")
  34.  
  35.     elif command == 'Insert':
  36.         index= int(token[1])
  37.         tank_name= token[2]
  38.         if not index_in_range(index, len(owned_tanks)):
  39.             print('Index out of range')
  40.             continue
  41.         if tank_name in owned_tanks:
  42.             print('Tank is already bought')
  43.         owned_tanks.insert(index, tank_name)
  44.         print('Tank successfully bought')
  45.  
  46. print(', '.join(owned_tanks))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement