Advertisement
simeonshopov

Weaponsmith

Jan 22nd, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. parts = input().split('|')
  2.  
  3. while True:
  4.     command = input()
  5.     if command == 'Done':
  6.         break
  7.     else:
  8.         tokens = command.split(' ')
  9.         cmd = tokens[0]
  10.         if cmd == 'Move':
  11.             direction = tokens[1]
  12.             idx = int(tokens[2])
  13.             if direction == 'Left':
  14.                 if 0 < idx < len(parts):
  15.                     parts.insert(idx - 1, parts.pop(idx))
  16.             elif direction == 'Right':
  17.                 if len(parts) - 1 > idx >= 0:
  18.                     parts.insert(idx + 1, parts.pop(idx))
  19.         if cmd == 'Check':
  20.             typo = tokens[1]
  21.             if typo == 'Even':
  22.                 print(' '.join([parts[x] for x in range(len(parts)) if x % 2 == 0]))
  23.             elif typo == 'Odd':
  24.                 print(' '.join([parts[x] for x in range(len(parts)) if x % 2 != 0]))
  25.  
  26. weapon = ''.join(parts)
  27. print(f'You crafted {weapon}!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement