Question

In: Computer Science

I'm working on a to-do list program in Python 2. I'm trying to delete an item...

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"

Solutions

Expert Solution

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: "))


Related Solutions

I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data...
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data from a CSV file, which has no names, just numbers. All I did was to read a .csv file. How do I pull data from three columns which contains about 1500 rows with just numbers and make a scatter plot with two in the x-axis and the third in the y-axis?
PYTHON--- regarding a hash table, why would it be bad to delete an item to successive...
PYTHON--- regarding a hash table, why would it be bad to delete an item to successive searches or insertions that uses open addressing
You are asked to delete the last occurrence of an item from a linked list. So,...
You are asked to delete the last occurrence of an item from a linked list. So, for instance: Input: 2 -> 3 -> 2 -> 4 Delete last occurrence of 2, result: 2 -> 3 -> 4 Implement the following method to do the deletion. You may NOT use or implement helper methods - all your code must be implemented inside the given method. You may NOT use recursion. public class Node { public int data; public Node next; }...
I'm trying to use Jupyter (python) to convert the contents of a pkl file into a...
I'm trying to use Jupyter (python) to convert the contents of a pkl file into a dictionary, WITHOUT using pandas. I'm able to import pickle and can open my file...but I'm not sure how to create the dictionary.
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list....
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list. So if the item is 7 and the list is [1,3,7,4,7,3,7,2], the result is [1,3,7,4,7,3,2] 2- Use LinkList. Write removeAll(int n). Deletes all occurrences of an item n from a linked list. So if the item is 7 and the list1 is [1,3,7,4,7,3,2] , then list1.removeAll(7) then list1 becomes [1,3,4,3,2]. Demonstrate by displaying the list contents before and after calling the above methods. Eg:...
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list....
1- Use LinkList. Write removeLast(n). Delete the last occurrence of an item from a linked list. So if the item is 7 and the list is [1,3,7,4,7,3,7,2], the result is [1,3,7,4,7,3,2] 2- Use LinkList. Write removeAll(int n). Deletes all occurrences of an item n from a linked list. So if the item is 7 and the list1 is [1,3,7,4,7,3,2] , then list1.removeAll(7) then list1 becomes [1,3,4,3,2]. Demonstrate by displaying the list contents before and after calling the above methods. Eg:...
1- Function 1: to delete a node in the head of the list. 2- Function 2:...
1- Function 1: to delete a node in the head of the list. 2- Function 2: to delete a node in the end of the list. 3- Function 3: to delete a node in the middle of the list. Ask the user the value of the node to delete. 4- Test the three functions in the main() and display the new list after each delete. #include <iostream> using namespace std; struct node { int num; node * nextptr; }*head,*curnode; node...
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
2.13 Program: Food receipt (Python 3) 1.Enter food item name: hot dog Enter item price: 2...
2.13 Program: Food receipt (Python 3) 1.Enter food item name: hot dog Enter item price: 2 Enter item quantity: 5 RECEIPT 5 hot dog @ $ 2.0 = $ 10.0 Total cost: $ 10.0 2.Enter food item name: hot dog Enter item price: 2 Enter item quantity: 5 RECEIPT 5 hot dog @ $ 2.0 = $ 10.0 Total cost: $ 10.0 Enter second food item name: ice cream Enter item price: 2.50 Enter item quantity: 4 RECEIPT 5 hot...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT