Guest User

Untitled

a guest
Jun 30th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. contacts = input().split()
  2.  
  3. while True:
  4.     line = input()
  5.     tokens = line.split()
  6.     command = tokens[0]
  7.     if command == 'Add':
  8.         name = tokens[1]
  9.         index = int(tokens[2])
  10.         if name not in contacts:
  11.             contacts.append(name)
  12.         else:
  13.             if 0 <= index < len(contacts):
  14.                 contacts.insert(index, name)
  15.  
  16.     elif command == 'Remove':
  17.         index = int(tokens[1])
  18.         if 0 <= index < len(contacts):
  19.             contacts.pop(index)
  20.  
  21.     elif command == 'Export':
  22.         start_index = int(tokens[1])
  23.         count = int(tokens[2])
  24.         if 0 <= index < len(contacts):
  25.             if count <= len(contacts):
  26.                 for i in range(start_index, count):
  27.                     print(contacts[i], end=' ')
  28.  
  29.             else:
  30.                 for i in range(start_index, len(contacts)):
  31.                     print(contacts[i], end=' ')
  32.             print()
  33.  
  34.     elif command == 'Print':
  35.         print('Contacts: ', end='')
  36.         if tokens[1] == 'Normal':
  37.             print(' '.join(contacts))
  38.         elif tokens[1] == 'Reversed':
  39.             contacts.reverse()
  40.             print(' '.join(contacts))
  41.         break
Add Comment
Please, Sign In to add comment