I wrote a program that receives from the user one string representing a shopping list. The program asks the user to enter a number between 1 and 9. Depending on the number received, do one of the following: And after making a user selection, the user returns to the main menu until they select number 9 to exit. The syntax is correct but the program does not print what is needed. How to fix it?
def shopping_list(my_str):
my_list = my_str.split(",")
i = input("Please choose a number between 1 and 9: ")
while i in range(1, 10):
if i == 1:
print("My shopping list:", my_list)
continue
elif i == 2:
print("The number of items in my shopping list:", len(my_list))
continue
elif i == 3:
product = input("Please enter a product name: ")
if product in my_list:
print("This product is in the shopping list.")
else:
print("This item is not in the shopping list.")
continue
elif i == 4:
product = input("Please enter a product name: ")
print("The item", product, "shows", my_list.count(product), "in the list")
continue
elif i == 5:
product = input("Please enter a product name: ")
new_list = my_list.remove(product)
print("The item", product, "remove from the list. The new list is", new_list)
continue
elif i == 6:
product = input("Please enter a product name: ")
my_list += product
print("The item", product, " add to the list. The new list is", my_list)
continue
elif i == 7:
new_list = []
for product in my_list:
if len(product) < 3 or not(product.isalpha()):
new_list += product
continue
elif i == 8:
print(list(set(my_list)))
continue
else:
break
shopping_list("Milk,Cottage,Tomatoes")
elifso no other code will be executed : remove all thecontinuestatementinput()returns a string value, and thereforewhile i in range(1, 10)will never execute.