二手产品经理

二手产品经理

THIS IS RENO

Arrays - 33 Days - Learn Python Online in 100 Days

Record#

Catbox

  1. Continuing to learn about operations on arrays today.

  2. Define an array: mylist = []

  3. Add content to the array: mylist.append("value")
    Catbox

  4. Remove content from the array: mylist.remove("value")
    Catbox

  5. 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.

  6. 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()
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.