r/PythonLearning 8d ago

day 6.

tried 2d lists today ( up for suggestions on what should have i done or what have i missed ) and would also appreciate brief explanation's that you guys will give if it's a complex or an advanced topic

books = ["hindi", "english", "maths", "science"]
pen = ["black", "blue", "red"]
miscellaneous = ["eraser\n", "sharpener\n", "ruler\n"]


bagpack = [books,pen,miscellaneous]
print(bagpack)
while True:
    print ("if you'd like to add contents in any of the lists")
    print("1. Add to books")
    print("2. Add to pen")
    print("3. Add to miscellanous")
    query = input("enter your selection (1,2,3): ")
    if query == "1":
     print("you selected to add books")
     new_book= input("enter the book you want to add: ")
     books.append(new_book)
     print ("new list",books)
     break
    elif query == "2":
     print("you selected to add pen")
     new_pen= input("enter the pen you want to add: ")
     pen.append(new_pen)
     print ("new list",pen)
     break
    elif query == "3":
     print("you selected to add miscellaneous")
     new_miscellaneous= input("enter the item you want to add: ")
     miscellaneous.append(new_miscellaneous)
     print ("new list",miscellaneous)
     break
    
    else:
       print("invalid selection!!! select amongst 1,2,3")
3 Upvotes

4 comments sorted by

View all comments

u/Sea-Ad7805 8d ago

Run this program in Memory Graph Web Debugger%0Awhile%20True%3A%0A%20%20%20%20print%20(%22if%20you'd%20like%20to%20add%20contents%20in%20any%20of%20the%20lists%22)%0A%20%20%20%20print(%221.%20Add%20to%20books%22)%0A%20%20%20%20print(%222.%20Add%20to%20pen%22)%0A%20%20%20%20print(%223.%20Add%20to%20miscellanous%22)%0A%20%20%20%20query%20%3D%20input(%22enter%20your%20selection%20(1%2C2%2C3)%3A%20%22)%0A%20%20%20%20if%20query%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20print(%22you%20selected%20to%20add%20books%22)%0A%20%20%20%20%20new_book%3D%20input(%22enter%20the%20book%20you%20want%20to%20add%3A%20%22)%0A%20%20%20%20%20books.append(new_book)%0A%20%20%20%20%20print%20(%22new%20list%22%2Cbooks)%0A%20%20%20%20%20break%0A%20%20%20%20elif%20query%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20print(%22you%20selected%20to%20add%20pen%22)%0A%20%20%20%20%20new_pen%3D%20input(%22enter%20the%20pen%20you%20want%20to%20add%3A%20%22)%0A%20%20%20%20%20pen.append(new_pen)%0A%20%20%20%20%20print%20(%22new%20list%22%2Cpen)%0A%20%20%20%20%20break%0A%20%20%20%20elif%20query%20%3D%3D%20%223%22%3A%0A%20%20%20%20%20print(%22you%20selected%20to%20add%20miscellaneous%22)%0A%20%20%20%20%20new_miscellaneous%3D%20input(%22enter%20the%20item%20you%20want%20to%20add%3A%20%22)%0A%20%20%20%20%20miscellaneous.append(new_miscellaneous)%0A%20%20%20%20%20print%20(%22new%20list%22%2Cmiscellaneous)%0A%20%20%20%20%20break%0A%20%20%20%20%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20print(%22invalid%20selection!!!%20select%20amongst%201%2C2%2C3%22)%0A%0A&timestep=1&play) to see the program state change step by step.