Advertisement
bl00dt3ars

Untitled

Aug 17th, 2021 (edited)
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. products = input().split("|")
  2. command = input()
  3.  
  4. while not command == "Shop!":
  5.     new_command = command.split("%")
  6.     command_name = new_command[0]
  7.     first_product = new_command[1]
  8.  
  9.     if command_name == "Important":
  10.         if first_product in products:
  11.             products.remove(first_product)
  12.         products.insert(0, first_product)
  13.     elif command_name == "Add":
  14.         if first_product not in products:
  15.             products.append(first_product)
  16.         else:
  17.             print("The product is already in the list.")
  18.     elif command_name == "Swap":
  19.         second_product = new_command[2]
  20.         if first_product in products and second_product in products:
  21.             index_one = products.index(first_product)
  22.             index_two = products.index(second_product)
  23.             products[index_one], products[index_two] = products[index_two], products[index_one]
  24.         else:
  25.             if first_product not in products:
  26.                 print(f"Product {first_product} missing!")
  27.             else:
  28.                 print(f"Product {second_product} missing!")
  29.     elif command_name == "Remove":
  30.         if first_product in products:
  31.             products.remove(first_product)
  32.         else:
  33.             print(f"Product {first_product} isn't in the list.")
  34.     command = input()
  35.    
  36. for i in range(len(products)):
  37.     print(f'{i + 1}. {products[i]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement