Sichanov

phone_shop

Oct 24th, 2021
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. phones = input().split(', ')
  2.  
  3. command = input().split(' - ')
  4.  
  5. while not command[0] == 'End':
  6.     action = command[0]
  7.     if action == 'Add':
  8.         phone = command[1]
  9.         if phone not in phones:
  10.             phones.append(phone)
  11.     elif action == 'Remove':
  12.         phone = command[1]
  13.         if phone in phones:
  14.             phones.remove(phone)
  15.     elif action == 'Bonus phone':
  16.         old_phone = command[1].split(':')[0]
  17.         new_phone = command[1].split(':')[1]
  18.         if old_phone in phones:
  19.             phones.insert(phones.index(old_phone) + 1, new_phone)
  20.     elif action == 'Last':
  21.         phone = command[1]
  22.         if phone in phones:
  23.             phones.append(phones.pop(phones.index(phone)))
  24.     command = input().split(' - ')
  25.  
  26. print(*phones, sep=', ')
Advertisement
Add Comment
Please, Sign In to add comment