Advertisement
GeorgiLukanov87

02_numbers_mid_exam_2022

Jun 26th, 2022
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # 02.Numbers , Mid Exam Fundamentals Python June.2022
  2.  
  3.  
  4. data = list(map(int, input().split(' ')))
  5. command = input()
  6. less_than_collapse = []
  7. while not command == 'Finish':
  8.     details = command.split()
  9.     if details[0] == 'Add':
  10.         add_value = int(details[1])
  11.         data.append(add_value)
  12.  
  13.     elif details[0] == 'Remove':
  14.         remove_value = int(details[1])
  15.         if remove_value in data:
  16.             data.remove(remove_value)
  17.  
  18.     elif details[0] == 'Replace':
  19.         value = int(details[1])
  20.         replace = int(details[2])
  21.         for index, el in enumerate(data):
  22.             if el == value:
  23.                 data[index] = replace
  24.                 break
  25.  
  26.     elif details[0] == 'Collapse':
  27.         collapse_value = int(details[1])
  28.         for el in data:
  29.             if not el < collapse_value:
  30.                 less_than_collapse.append(el)
  31.         data.clear()
  32.         data = less_than_collapse
  33.  
  34.     command = input()
  35.  
  36. print(*data, sep=" ")
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement