Guest User

Untitled

a guest
Oct 4th, 2020
74
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 start_index + count > len(contacts):
  23. print(f"{' '.join(contacts[start_index:])}")
  24. else:
  25. print(f"{' '.join(contacts[start_index:start_index + count])}")
  26.  
  27. elif action == 'Print':
  28. way = tokens[1]
  29. if way == 'Normal':
  30. print(f"Contacts: {' '.join(contacts)}")
  31. break
  32. else:
  33. print(f"Contacts: {' '.join(contacts[::-1])}")
  34. break
  35.  
RAW Paste Data