Record#
-
Continuing to learn about operations on arrays 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 stop, so it is necessary to first check with if value in mylist. If true, then remove, if false, provide 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 to add?\n")
mylist.append(item)
def edit():
item = input("Which schedule is 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()