二手产品经理

二手产品经理

THIS IS RENO

Array - 33 days - Learn Python online for 100 days

Record#

Catbox

  1. Continue learning about array operations 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 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.

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