nord vpnnord vpn
Ad

Pritam's Booklist

mail@pastecode.io avatar
unknown
python
2 years ago
1.9 kB
4
Indexable
Never
def display(booklist):
    print("""Pritam's Booklist
    ********""")
    for i in range(len(booklist)):
        print("Book no. ", i, ": ", booklist[i])
    print("    ********")

booklist = []

while True:
    print("""
    1. Add book name
    2. Display booklist
    3. Edit booklist
    4. Search booklist
    5. Sort booklist
    6. Delete booklist
    7. Reverse booklist
    8. Count books number
    9. Exit
    """)
    f = int(input("Choose option: "))
    if(f==1):
        n = int(input("How many books do you want to add: "))
        for i in range(n):
            name = input("Enter book name to add: ")
            booklist.append(name)
        print("book added to the list")
    elif(f==2):
        display(booklist)
    elif(f==3):
        display(booklist)
        edit = int(input("Enter book's number to edit: "))
        if edit<0 or edit>=len(booklist):
            print("Wrong Input")
            continue
        name = input("Enter new name: ")
        booklist[edit] = name
    elif(f==4):
        name = input("Which book do you want to search:")
        if name in booklist:
            print("Yes!!! The book is in the list")
        else:
            print("No!!! The book is not in the list")
    elif(f==5):
        booklist.sort()
        print("Booklist sorted.")
        #display(booklist)
    elif(f==6):
        display(booklist)
        delete = int(input("Enter book's number to delete: "))
        if edit<0 or edit>=len(booklist):
            print("Wrong Input")
            continue
        del booklist[delete]
        print("book deleted from list")
    elif(f==7):
        booklist.reverse()
        print("Booklist reversed")
    elif(f==8):
        print("Booklist have ", len(booklist), "books")
    elif(f==9):
        break
    else:
        print("Wrong Input. Try again.")

nord vpnnord vpn
Ad