Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contacts = input().split()
- while True:
- command = input().split()
- action = command[0]
- if action == "Add":
- contact = command[1]
- index = int(command[2])
- if contact not in contacts:
- contacts.append(contact)
- else:
- if 0 <= index < len(contacts):
- contacts.insert(index, contact)
- elif action == "Remove":
- index = int(command[1])
- if 0 <= index < len(contacts):
- contacts.pop(index)
- elif action == "Export":
- start_index = int(command[1])
- count = int(command[2])
- # If the count requested is more than the contacts- just print them to the end.
- if count > len(contacts):
- count = len(contacts)
- # Print the next {count} contacts starting from the given {startIndex} (including), separated by a single space.
- if 0 <= start_index < count:
- for contact in range(start_index, count):
- print(contacts[contact], end=" ")
- print()
- elif action == "Print":
- status = command[1]
- print("Contacts: ", end="")
- if status == "Normal":
- print(" ".join(contacts))
- elif status == "Reversed":
- contacts.reverse()
- print(" ".join(contacts))
- break
Advertisement
Add Comment
Please, Sign In to add comment