Advertisement
GeorgiLukanov87

02. Friends_maintenance , Mid Exam Fundamentals Python June.2022

Jun 27th, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # WITHOUT JUDGE TESTING !
  2. # 02. Friends_maintenance , Mid Exam Fundamentals Python June.2022
  3.  
  4. def is_index_valid(some_list, some_index):
  5.     if 0 <= some_index < len(some_list):
  6.         return True
  7.     return False
  8.  
  9.  
  10. def is_name_valid(some_list, some_name):
  11.     if (some_name in some_list) and (some_name != 'Blacklisted') and (some_name != 'Lost'):
  12.         return True
  13.     return False
  14.  
  15.  
  16. data = input().split(", ")
  17. command = input()
  18.  
  19. blacklisted_names = []
  20. lost_names = []
  21.  
  22. while not command == 'Report':
  23.     details = command.split(' ')
  24.  
  25.     if details[0] == 'Blacklist':
  26.         move_to_blacklist = details[1]
  27.         if move_to_blacklist in data:
  28.             index_name = data.index(move_to_blacklist)
  29.             data[index_name] = 'Blacklisted'
  30.             blacklisted_names.append(move_to_blacklist)
  31.             print(f'{move_to_blacklist} was blacklisted.')
  32.         else:
  33.             print(f'{move_to_blacklist} was not found.')
  34.  
  35.     elif details[0] == 'Error':
  36.         index = int(details[1])
  37.         name = data[index]
  38.         if is_index_valid(data, index) and is_name_valid(data, name):
  39.             data[index] = 'Lost'
  40.             print(f'{name} was lost due to an error.')
  41.             lost_names.append(name)
  42.  
  43.     elif details[0] == 'Change':
  44.         change_index = int(details[1])
  45.         new_name = details[2]
  46.         if is_index_valid(data, change_index):
  47.             data[change_index] = new_name
  48.  
  49.     command = input()
  50.  
  51. print(f'Blacklisted names: {len(blacklisted_names)}')
  52. print(f'Lost names: {len(lost_names)}')
  53. print(' '.join(data))
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement