If you have any questions, comments or issues with this project please post them here!
This one is for all the list makers. Built a customized to do list today.
https://replit.com/@JackAdem/Day-033-Project-33-To-Do-List-Manager?v=1
Day 33 of #Replit100DaysOfCode #100DaysOfCode.
Question:
I can’t figure out why this method of subroutines isn’t properly appending and removing from the list. Any insight?
Repl link:
todoList = []
def viewList():
for item in todoList:
print(item)
print()
def addList():
item = input("Add item to list: ")
todoList.append(item)
viewList()
def editList():
item = input("Remove item from list: ")
todoList.remove(item)
viewList()
while True:
print("ToDo List Manager")
print()
userAction = input("Do you want to view, add, or edit the todo list? ")
if userAction == "view" or "View":
viewList()
elif userAction == "add" or "Add":
addList()
elif userAction == "edit" or "Edit":
editList()
print()
viewList()
print()
update = input("More updates? ")
if update == "yes":
continue
else:
break
The issue is in
if userAction == "view" or "View":
elif userAction == "add" or "Add":
elif userAction == "edit" or "Edit":
the left half is correct if userAction == "view"
but the right half or "View"
is incorrect. You need to use :
if userAction == "view" or userAction == "View":
elif userAction == "add" or userAction == "Add":
elif userAction == "edit" or userAction == "Edit":
No matter what userAction is it will always attempt to “View” the list, never allowing you to add anything to it, this is because when you just have or "View"
it’s saying if “View” exists which is True
This is also because “View” is first before “Add” or “Edit”
if you were to re order them so that userAction == “add” or userAction == “Add”: was first:
It would always “Add” to the list no matter what userAction was.
from Day 8:
This is explained well here in this video at 2:10.
You could also just use .lower()
and then you wouldn’t even need the ors
userAction = input("Do you want to view, add, or edit the todo list? ").lower()
if userAction == "view":
viewList()
elif userAction == "add":
addList()
elif userAction == "edit":
editList()
thanks! awesome response