Advertisement
GeorgiLukanov87

03. School Library_mid_exam_2022

Jun 26th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. # 03. School Library , Mid Exam Fundamentals Python June.2022
  2.  
  3.  
  4. books = input().split('&')
  5. command = input()
  6.  
  7. while not command == 'Done':
  8.     details = command.split(' | ')
  9.     if details[0] == 'Add Book':
  10.         name = details[1]
  11.         if name not in books:
  12.             books.insert(0, name)
  13.  
  14.     elif details[0] == 'Take Book':
  15.         name = details[1]
  16.         if name in books:
  17.             books.remove(name)
  18.  
  19.     elif details[0] == 'Swap Books':
  20.         name1 = details[1]
  21.         name2 = details[2]
  22.         if (name1 in books) and (name2 in books):
  23.             index1 = books.index(name1)
  24.             index2 = books.index(name2)
  25.             books[index1], books[index2] = books[index2], books[index1]
  26.  
  27.     elif details[0] == 'Insert Book':
  28.         insert_name = details[1]
  29.         if insert_name not in books:
  30.             books.append(insert_name)
  31.  
  32.     elif details[0] == 'Check Book':
  33.         index = int(details[1])
  34.         if 0 <= index < len(books):
  35.             print(books[index])
  36.  
  37.     command = input()
  38. print(*books, sep=", ")
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement