Advertisement
GeorgiLukanov87

shopping_list

Jun 21st, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. products = input().split('!')
  2. command = input()
  3.  
  4. while not command == 'Go Shopping!':
  5.     command = command.split()
  6.    
  7.     if command[0] == 'Urgent':
  8.         item = command[1]
  9.         if item not in products:
  10.             products.insert(0, item)
  11.            
  12.     elif command[0] == 'Unnecessary':
  13.         item = command[1]
  14.         if item in products:
  15.             products.remove(item)
  16.            
  17.     elif command[0] == 'Correct':
  18.         old_item = command[1]
  19.         new_item = command[2]
  20.         new_products = []
  21.         if old_item in products:
  22.             for word in products:
  23.                 new_products.append(word)
  24.                 if word == old_item:
  25.                     result = word.replace(old_item, new_item)
  26.                     new_products.append(result)
  27.                     new_products.remove(old_item)
  28.             products = new_products
  29.            
  30.     elif command[0] == 'Rearrange':
  31.         item = command[1]
  32.         if item in products:
  33.             products.remove(item)
  34.             products.append(item)
  35.  
  36.     command = input()
  37.    
  38. print(', '.join(products))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement