Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. School Library , Mid Exam Fundamentals Python June.2022
- books = input().split('&')
- command = input()
- while not command == 'Done':
- details = command.split(' | ')
- if details[0] == 'Add Book':
- name = details[1]
- if name not in books:
- books.insert(0, name)
- elif details[0] == 'Take Book':
- name = details[1]
- if name in books:
- books.remove(name)
- elif details[0] == 'Swap Books':
- name1 = details[1]
- name2 = details[2]
- if (name1 in books) and (name2 in books):
- index1 = books.index(name1)
- index2 = books.index(name2)
- books[index1], books[index2] = books[index2], books[index1]
- elif details[0] == 'Insert Book':
- insert_name = details[1]
- if insert_name not in books:
- books.append(insert_name)
- elif details[0] == 'Check Book':
- index = int(details[1])
- if 0 <= index < len(books):
- print(books[index])
- command = input()
- print(*books, sep=", ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement