exDotaPro

school_library

Apr 5th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. shelf = input().split("&")
  2. line = input().split(" | ")
  3.  
  4. while line[0] != "Done":
  5.     command = line[0]
  6.     book = line[1]  # може и е по-добре да е тук, за да не се повтаря на всякъде
  7.  
  8.     if command == "Add Book":
  9.         # for book in line[1:]: излишно e
  10.         if book not in shelf:
  11.             shelf.insert(0, book)
  12.     elif command == "Take Book":
  13.         if book in shelf:
  14.             shelf.remove(book)
  15.     elif command == "Swap Books":
  16.         book_2 = line[2]
  17.         if book in shelf and book_2 in shelf:
  18.             book_idx = shelf.index(book)
  19.             book_2_idx = shelf.index(book_2)
  20.             shelf[book_idx], shelf[book_2_idx] = shelf[book_2_idx], shelf[book_idx]
  21.     elif command == "Insert Book":
  22.         # shelf.remove(book) няма как да кажеш remove на нещо, което още не си append-нал :D :D
  23.         shelf.append(book)
  24.     elif command == "Check Book":
  25.         index = int(line[1])
  26.         if not index > len(shelf):  # If the index is invalid, ignore the command.
  27.             print(shelf[index])
  28.  
  29.     line = input().split(" | ")
  30.  
  31. print(", ".join(shelf))
Add Comment
Please, Sign In to add comment