Sichanov

school_library

Oct 24th, 2021
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. books = input().split('&')
  2.  
  3. command = input().split(' | ')
  4.  
  5. while not command[0] == 'Done':
  6.     action = command[0]
  7.     book = command[1]
  8.     if action == 'Add Book':
  9.         if book not in books:
  10.             books.insert(0, book)
  11.     elif action == 'Take Book':
  12.         if book in books:
  13.             books.remove(book)
  14.     elif action == 'Swap Books':
  15.         book2 = command[2]
  16.         if book in books and book2 in books:
  17.            index1 = books.index(book)
  18.            index2 = books.index(book2)
  19.            books[index1], books[index2] = books[index2], books[index1]
  20.     elif action == 'Insert Book':
  21.         if book not in books:
  22.             books.append(book)
  23.     elif action == 'Check Book':
  24.         if 0 <= int(command[1]) < len(books):
  25.             print(f'{books[int(command[1])]}')
  26.     command = input().split(' | ')
  27.  
  28. print(*books, sep=', ')
Advertisement
Add Comment
Please, Sign In to add comment