Advertisement
Stily

Untitled

Feb 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. shelf=input().split('&')
  2. command=input()
  3. while command!='Done':
  4. command_list=command.split(' | ')
  5. if command_list[0]=='Add Book':
  6. book_name=command_list[1]
  7. if book_name not in shelf:
  8. shelf.insert(0,book_name)
  9. elif command_list[0]=='Take Book':
  10. book_name=command_list[1]
  11. shelf.remove(book_name)
  12. elif command_list[0]=='Swap Books':
  13. book1=command_list[1]
  14. book2=command_list[2]
  15. a, b = shelf.index(book1), shelf.index(book2)
  16. shelf[a],shelf[b]=shelf[b], shelf[a]
  17. elif command_list[0]=='Insert Book':
  18. book_name = command_list[1]
  19. shelf.insert(len(shelf), book_name)
  20. elif command_list[0]=='Check Book':
  21. index=int(command_list[1])
  22. if 0<=index<len(shelf):
  23. print(shelf[index])
  24. command=input()
  25. print(', '.join(shelf))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement