Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contacts = input().split()
- while True:
- line = input()
- tokens = line.split()
- command = tokens[0]
- if command == 'Add':
- name = tokens[1]
- index = int(tokens[2])
- if name not in contacts:
- contacts.append(name)
- else:
- if 0 <= index < len(contacts):
- contacts.insert(index, name)
- elif command == 'Remove':
- index = int(tokens[1])
- if 0 <= index < len(contacts):
- contacts.pop(index)
- elif command == 'Export':
- start_index = int(tokens[1])
- count = int(tokens[2])
- if 0 <= index < len(contacts):
- if count <= len(contacts):
- for i in range(start_index, count):
- print(contacts[i], end=' ')
- else:
- for i in range(start_index, len(contacts)):
- print(contacts[i], end=' ')
- print()
- elif command == 'Print':
- print('Contacts: ', end='')
- if tokens[1] == 'Normal':
- print(' '.join(contacts))
- elif tokens[1] == 'Reversed':
- contacts.reverse()
- print(' '.join(contacts))
- break
Add Comment
Please, Sign In to add comment