Advertisement
Spocoman

02. Shopping List

Nov 9th, 2023
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. list_products = input().split('!')
  2.  
  3. command = input()
  4.  
  5. while command != "Go Shopping!":
  6.     tokens = command.split(' ')
  7.     command = tokens[0]
  8.     product = tokens[1]
  9.  
  10.     if command == "Urgent" and product not in list_products:
  11.         list_products.insert(0, product)
  12.     elif command == "Unnecessary" and product in list_products:
  13.         list_products.remove(product)
  14.     elif command == "Correct" and product in list_products:
  15.         new_product = tokens[2]
  16.         list_products[list_products.index(product)] = new_product
  17.     elif command == "Rearrange" and product in list_products:
  18.         list_products.append(list_products.pop(list_products.index(product)))
  19.  
  20.     command = input()
  21.  
  22. print(", ".join(list_products))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement