Sichanov

friend_list_maintenance

Oct 24th, 2021
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. def is_valid_index(list, index):
  2.     if 0 <= index < len(list):
  3.         return True
  4.  
  5.  
  6. friends = input().split(', ')
  7. counter_blacklisted = 0
  8. counter_error = 0
  9. command = input().split()
  10.  
  11. while not command[0] == 'Report':
  12.     action = command[0]
  13.     if action == 'Blacklist':
  14.         name = command[1]
  15.         if name in friends:
  16.             friends[friends.index(name)] = 'Blacklisted'
  17.             counter_blacklisted += 1
  18.             print(f'{name} was blacklisted.')
  19.         else:
  20.             print(f"{name} was not found.")
  21.     elif action == 'Error':
  22.         index = int(command[1])
  23.         if is_valid_index(friends, index):
  24.             if not friends[index] == 'Blacklisted' and not friends[index] == 'Lost':
  25.                 print(f'{friends[index]} was lost due to an error.')
  26.                 friends[index] = 'Lost'
  27.                 counter_error += 1
  28.     elif action == 'Change':
  29.         index = int(command[1])
  30.         new_name = command[2]
  31.         if is_valid_index(friends, index):
  32.             print(f'{friends[index]} changed his username to {new_name}')
  33.             friends[index] = new_name
  34.  
  35.     command = input().split()
  36.  
  37. print(f"Blacklisted names: {counter_blacklisted}")
  38. print(f"Lost names: {counter_error}")
  39. print(*friends)
Advertisement
Add Comment
Please, Sign In to add comment