Guest User

Untitled

a guest
Sep 9th, 2020
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. contacts = input().split()
  2.  
  3. while True:
  4. command = input()
  5. tokens = command.split()
  6. action = tokens[0]
  7. if action == 'Add':
  8. name = tokens[1]
  9. if name not in contacts:
  10. contacts.append(name)
  11. else:
  12. index = int(tokens[2])
  13. if 0 <= index < len(contacts):
  14. contacts.insert(index, name)
  15. elif action == 'Remove':
  16. index = int(tokens[1])
  17. if 0 <= index < len(contacts):
  18. contacts.pop(index)
  19. elif action == 'Export':
  20. start_index = int(tokens[1])
  21. count = int(tokens[2])
  22. if 0 <= start_index < len(contacts):
  23. if count > len(contacts[start_index:]):
  24. print(f"{' '.join(contacts[start_index:])}")
  25. else:
  26. print(f"{' '.join(contacts[start_index:count])}")
  27.  
  28. elif action == 'Print':
  29. way = tokens[1]
  30. if way == 'Normal':
  31. print(f"Contacts: {' '.join(contacts)}")
  32. break
  33. elif way == 'Reversed':
  34. print(f"Contacts: {' '.join(contacts[::-1])}")
  35. break
  36.  
RAW Paste Data