Record#
-
Continue learning about array operations today.
-
Define an array: mylist = []
-
Add content to the array: mylist.append("value")
-
Remove content from the array: mylist.remove("value")
-
When removing content that does not exist in the array, the program will throw an error and interrupt, so you need to use if value in mylist. If it's true, remove it; if it's false, give a friendly operation prompt.
-
Today's exercise is to write a schedule program that can add and delete to-do items.
CODE#
print("\033[31mSchedule\033[0m")
mylist = []
def view():
for item in mylist:
print(item)
def add():
item = input("What schedule do you want to add?\n")
mylist.append(item)
def edit():
item = input("Which schedule has been completed?\n")
if item in mylist:
mylist.remove(item)
else:
print(f"{item} is not in the schedule")
view()
while True:
menu = input("Menu: view - add - edit:\n")
if menu == "view":
view()
elif menu =="add":
add()
elif menu == "edit":
edit()