In: Computer Science
I'm working on a to-do list program in Python 2. I'm trying to delete an item from the list and I'm not sure what I'm missing to do that. I haven't been able to get it to delete by string or by index number. Also, I'm trying to get the menu to run again after the user completes the add/delete/etc options. Do I need to put menu() menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue: ")) after each if statement?
def menu():
print "[1] Add an item to the list\n[2] Delete an item from the list\n[3] Print the list\n[4] Print the list in reverse\n[5] Quit the program"
menu()
menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue: "))
todo_list = []
i = 0
count = 0
while menu_option != 5:
if menu_option == 1:
addedItem = str(input("Please add an item to the To-Do List. Type 'done' when you have entered all items."))
if addedItem == 'done':
break
todo_list.append(addedItem)
i += 1
count += 1
else: i += 1
if menu_option == 2:
deletedItem = str(input("Please enter the number of the item you would like to delete."))
todo_list.remove(deletedItem)
print "Item " + str(deletedItem) + " has been deleted"
def menu():
print("[1] Add an item to the list\n[2] Delete an item from the list\n[3] Print the list\n[4] Print the list in reverse\n[5] Quit the program")
menu()
menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue: "))
todo_list = []
i = 0
count = 0
while menu_option != 5:
if menu_option == 1:
while(True):
addedItem = str(input("Please add an item to the To-Do List. Type 'done' when you have entered all items."))
if addedItem == 'done':
break
todo_list.append(addedItem)
i += 1
count += 1
elif menu_option == 2:
if(len(todo_list) == 0):
print("No items in todo_list. Please add items and then use option 2 to delete item.")
else:
deletedItem = str(input("Please enter the number of the item you would like to delete."))
todo_list.remove(deletedItem)
print("Item " + str(deletedItem) + " has been deleted")
menu()
menu_option = int(input("Welcome to your To-Do List. Please choose and option to continue: "))


