CS_Part_2_Module08Asssignment
CS_Part_2_Module08Asssignment
Note: Make sure your links are live and will go to the URL when
clicked. To do this, after pasting the URL, add a space. The URL will
automatically become a live hyperlink.
Code HS Lessons
CodeHS Lesson 8.5: Creating and Altering Data Structures Quiz (2 points)
URL:
https://codehs.com/student/1298751/section/268463/assignments
library = []
def add_book(book_name):
if book_name not in library:
library.append(book_name.title())
print(f"'{book_name}' has been added to the library!")
else:
print(f"'{book_name}' is already in the library.")
def search_book(book_name):
if book_name.title() in library:
CTE
Computer Science, Part 2
Module 8 Assignment
index = library.index(book_name.title())
print(f"'{book_name}' is in the library at position {index + 1}.")
else:
print(f"'{book_name}' is not in the library.")
def display_library():
if len(library) == 0:
print("The library is empty!")
else:
print("\nBooks in the Library:")
for book in library:
print(f"- {book}")
def sort_library():
library.sort()
print("\nThe library has been sorted alphabetically!")
def remove_book(book_name):
try:
library.remove(book_name.title())
print(f"'{book_name}' has been removed from the library!")
except ValueError:
print(f"'{book_name}' is not in the library!")
def main():
while True:
CTE
Computer Science, Part 2
Module 8 Assignment
print("\nLibrary Menu:")
print("1. Add a Book")
print("2. Search for a Book")
print("3. Display All Books")
print("4. Sort the Library")
print("5. Remove a Book")
print("6. Exit")
try:
choice = int(input("Enter your choice (1-6): "))
if choice == 1:
book_name = input("Enter the name of the book to add:
").strip()
add_book(book_name)
elif choice == 2:
book_name = input("Enter the name of the book to search for:
").strip()
search_book(book_name)
elif choice == 3:
display_library()
elif choice == 4:
sort_library()
elif choice == 5:
book_name = input("Enter the name of the book to remove:
").strip()
remove_book(book_name)
elif choice == 6:
print("Goodbye!")
CTE
Computer Science, Part 2
Module 8 Assignment
break
else:
print("Please enter a valid choice (1-6).")
except ValueError:
print("Invalid input. Please enter a number between 1 and 6.")
main()
CTE
Computer Science, Part 2
Module 8 Assignment
1. Users will interact with the program through a menu displayed in the
console
2. The console will display clear instructions
3. The program will prompt users to enter their choices of 1-6 to navigate
the system
4. The system will do functions such as adding, searching, or removing
books
User needs
Program functionality
Pseudocode or outline
CTE
Computer Science, Part 2
Module 8 Assignment
Main Module -
Add Book Module
Search Module
Display Module
Sort Module
Remove Book Module
CTE
Computer Science, Part 2
Module 8 Assignment
Describe how you have met the Design criteria for the Idea
Design and Refinement micro-credential.