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