Advertisement
go6odn28

easter_gift_

Apr 10th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. def outofstock(gifts_list, gift):
  2.     for i in range(len(gifts_list)):
  3.         if gift == gifts_list[i]:
  4.             gifts_list[i] = "None"
  5.     return gifts_list
  6.  
  7.  
  8. def required(gifts_list, gift, index):
  9.     if 0 <= index < len(gifts_list):
  10.         gifts_list[index] = gift
  11.     return gifts_list
  12.  
  13.  
  14. def justincase(gifts_list, gift):
  15.     gifts_list[-1] = gift
  16.     return gifts_list
  17.  
  18.  
  19. def final_print(gifts_list):
  20.     for i in gifts_list:
  21.         if i != "None":
  22.             print(i, end=" ")
  23.  
  24.  
  25. gifts_list = input().split()
  26. while True:
  27.     command = input().split()
  28.     if command[0].startswith("No"):
  29.         break
  30.     gift = command[1]
  31.     if command[0] == "OutOfStock":
  32.         gifts_list = outofstock(gifts_list, gift)
  33.     elif command[0] == "Required":
  34.         index = int(command[2])
  35.         gifts_list = required(gifts_list, gift, index)
  36.     elif command[0] == "JustInCase":
  37.         gifts_list = justincase(gifts_list, gift)
  38. final_print(gifts_list)
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement