Advertisement
Spocoman

03. Phone Shop

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