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?
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.
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...
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...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : at least 5 uppercase letters at least 5 lowercase letters at least 5 numbers No more than 20 characters in total I have managed to meet these conditions in individual python files but not in one. Ideally without importing...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : 5 uppercase letters 5 lowercase letters 5 numbers First letter must be capitilized The total characters must be 15 I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still...
I'm working on python code which is substring matching. For example, the given string is input...
I'm working on python code which is substring matching. For example, the given string is input "CTTGTGATCTCGTGTCGTGGGTAG", and a substring we want to find in the main one is "GTGG". So the code will print out the position and the substrings in the main which has exactly one different position. For example, start at position 4 the substring is GTGA since there is only one letter different, and so on. Even though we know that string index starts at 0,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT