bl00dt3ars

07. Easter Gifts (broscho)

Jul 8th, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. def is_out_of_stock(collection: list, gift: str):
  2.     easter_gift = gift
  3.     for el in collection:
  4.         if easter_gift == el:
  5.             collection[collection.index(el)] = "None"
  6.  
  7.     return collection
  8.  
  9.  
  10. def is_required(collection: list, gift: str, index: int):
  11.     easter_gift = gift
  12.     index_gift = index
  13.     if 0 <= index_gift <= len(collection) - 1:
  14.         for ch in range(len(collection)):
  15.             if index_gift == ch:
  16.                 collection[ch] = easter_gift
  17.  
  18.     return collection
  19.  
  20.  
  21. def just_in_case(collection: list, gift: str):
  22.     easter_gift = gift
  23.     collection[-1] = easter_gift
  24.  
  25.     return collection
  26.  
  27.  
  28. presents = input().split()
  29. command = input()
  30.  
  31. while command != "No Money":
  32.     cmd_arg = command.split()
  33.     command_type = str(cmd_arg[0])
  34.     command_gift = str(cmd_arg[1])
  35.     if command_type == "Required":
  36.         command_index = int(cmd_arg[2])
  37.         is_required(presents, command_gift, command_index)
  38.     elif command_type == "OutOfStock":
  39.         is_out_of_stock(presents, command_gift)
  40.     elif command_type == "JustInCase":
  41.         just_in_case(presents, command_gift)
  42.  
  43.     command = input()
  44.  
  45. [print(f"{el}", end=' ') for el in presents if not el == "None"]
Advertisement
Add Comment
Please, Sign In to add comment