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?
Write a program that prompts the user to insert an item into a stack, delete an...
Write a program that prompts the user to insert an item into a stack, delete an item from the stack, or display all the items in the stack. Assume that the stack maximum capacity is 10. Here is sample run . Stack operation menu: 1. Insert 2. Delete 3. Display 4. Quit
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
I'm trying to write a feet to meters and centimeters program and I'm looking for a...
I'm trying to write a feet to meters and centimeters program and I'm looking for a little help so I can see how close I got. It should do the following: Write a convertToMetric class that has the following field: standard - holds a double, standard length value in feet. The class should have the following methods: Constructor - that accepts a length in feet (as a double) and stores it in the standard field. setStandard - accepts a standard...
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.
MIPS Program I'm trying to write a program that will take in two numbers from the...
MIPS Program I'm trying to write a program that will take in two numbers from the user and output the sum at the end. However, I keep getting very wrong answers. For example, I add 2 and 2 and get 268501000. Help would be appreciated. .data #starts data use userIn1:    .word 4 #sets aside space for input    userIn2:    .word 4 #sets aside space for input total:    .word 4 #sets space aside for input    request:   ...
I'm trying to ask a series of questions with validation in python. example: What is your...
I'm trying to ask a series of questions with validation in python. example: What is your name? (if valid name then continue to question 2) What is your email? (if not valid then ask this question again, if valid then next question) How old are you? (again, if invalid then ask again, if valid then next. import re def get_new_artwork():     name_regex = "^(?=.{2,40}$)[a-zA-Z]+(?:[-'\s][a-zA-Z]+)*$"     email_regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'     while True:         name = input('Enter your name: ').title().strip()         if re.search(name_regex, name) is None:             print('Invalid...
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...
write a Python program (with comments) to do the following: Define a list list1 = [['Rose',...
write a Python program (with comments) to do the following: Define a list list1 = [['Rose', 'Daisy'], 7, 0, 5.5, [1, 22, 2.45, 3, 6, 5.8]] and print it. Print the length of list1 (i.e. number of items in list1) with a suitable message. Print the first character of the first string in the first item of list1 with a suitable message (HINT: The first item is the item with index 0). Print the sum of the last 4 numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT