Sichanov

coffee_lover

Oct 24th, 2021
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. coffee_list = input().split()
  2.  
  3. number_of_commands = int(input())
  4.  
  5. for each_command in range(number_of_commands):
  6.     command = input().split()
  7.     action = command[0]
  8.     if action == 'Include':
  9.         coffee = command[1]
  10.         coffee_list.append(coffee)
  11.     elif action == 'Remove':
  12.         first_last = command[1]
  13.         number_coffee = int(command[2])
  14.         if number_coffee < len(coffee_list):
  15.             if first_last == 'first':
  16.                 coffee_list = coffee_list[number_coffee:]
  17.             else:
  18.                 coffee_list = coffee_list[:-number_coffee]
  19.     elif action == 'Prefer':
  20.         index1 = int(command[1])
  21.         index2 = int(command[2])
  22.         if 0 <= index1 < len(coffee_list) and 0 <= index2 < len(coffee_list):
  23.             coffee_list[index1], coffee_list[index2] = coffee_list[index2], coffee_list[index1]
  24.     elif action == 'Reverse':
  25.         coffee_list.reverse()
  26.  
  27. print('Coffee:')
  28. print(*coffee_list)
  29.  
Advertisement
Add Comment
Please, Sign In to add comment