Shopping list: how do I get the commands to work?

When I run this program, the commands don’t work.
What am I doing wrong?

print("Welcome to best-shopping_list!")


shopping_list = {}


print("s: Show list")
print("a: add to list")
print("d: delete from list")
print("e: exit")

selection = input("CMD:")
while selection != "e":
    if selection == "s":
        for item in shopping_list:
            print(shopping_list[item])

    elif selection == "a":
        item = input("Enter an item: ")
        quantity = int(input("Enter the quantity: "))
        shopping_list[item] = quantity

    elif selection == "d":
        item = input("Enter an item: ")
        del(shopping_list[item])

    elif selection == "e":
        print("Shopping finished!")

Looks like an infinity loop. What is there to stop the loop? you don’t prompt for another input within the loop

Thank you! Could you please explain to me how I could solve it?:slightly_smiling_face:

1 Like

You first need to identify the problem.

Then you need to think about what steps you need to take to overcome the problem

in this case, you want to use input() to gain new input each iteration of the loop until exit.

1 Like

Thanks, again!:slight_smile: