Advertisement
DiYane

Shopping List

Sep 18th, 2023
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. groceries = input().split("!")
  2.  
  3. while True:
  4.     command_str = input()
  5.     if "Go Shopping!" in command_str:
  6.         break
  7.     command = command_str.split()
  8.     if "Urgent" in command and command[1] not in groceries:
  9.         item = command[1]
  10.         groceries.insert(0, item)
  11.     elif "Unnecessary" in command and command[1] in groceries:
  12.         item = command[1]
  13.         groceries.remove(item)
  14.     elif "Correct" in command and command[1] in groceries:
  15.         old_item = command[1]
  16.         new_item = command[2]
  17.         index_old = groceries.index(old_item)
  18.         groceries[index_old] = new_item
  19.     elif "Rearrange" in command and command[1] in groceries:
  20.         item = command[1]
  21.         groceries.remove(item)
  22.         groceries.append(item)
  23. print(", ".join(groceries))
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement