我正在使用数组或列表在Python中创建待办事项列表应用程序。我想检查包含所有“待办事项”的数组是否已满。如果它已满,我会通知用户该列表已满。我还是个初学者。
todo_list = ["1.)", "2.)", "3.)", "4.)", "5.)", "6.)", "7.)", "8.)", "9.)", "10.)"]
def addTask(taskName):
'''
this is a global variable to keep track of what index the last task was
placed in.
'''
global x
x = int(x)
num = x + 1
num = int(num)
taskName = str(taskName)
'''
This is what I tried to make the program start from the beginning if the
list was full.
'''
if x > list_length:
x = 0
todo_list[0] = None
todo_list[x] = str(num) + ".) " + taskName
x = x+1
print("Done!")
main()
解决办法:不必定义todo_list编号。只需定义最大尺寸,todo_list并检查长度todo_list是否大于最大尺寸。
todo_list = list()
MAX_SIZE = 10
add_task(taskName:str):
if len(todo_list) >= MAX_SIZE:
# code you want to run when todo_list is full
else:
todo_list.append("{}.) {}".format(len(todo_list)+1, taskName))
三个资料Q群下载不了也转发不了,先放这里Fine_tuning.zipLangChain.zipdata_clear.rar