Reputation:
inp = input("Would you want to (A)dd or (D)elete something from the list? (E to exit) ")
mylist = []
while inp != "E":
if inp == "A":
add = input("Enter an item to add: ")
mylist.append(add)
elif inp == "D":
delete = input("Enter an item to delete: ")
mylist.remove(delete)`
When I do this, my program continues to ask for an item to add. How do I get my loop to start over?
Upvotes: 0
Views: 50
Reputation: 2300
Move the first input()
within the while
loop:
while inp != "E":
inp = input("Would you want to (A)dd or (D)elete something from the list? (E to exit) ")
Upvotes: 0
Reputation: 2685
You have to call the inp
variable which is input under the while loop.
inp = ""
mylist = []
while inp != "E":
inp = input("Would you want to (A)dd or (D)elete something from the list? (E to exit) ")
if inp == "A":
add = input("Enter an item to add: ")
mylist.append(add)
elif inp == "D":
delete = input("Enter an item to delete: ")
mylist.remove(delete)
Upvotes: 1