啊啊啊啊啊吖

2019-03-12   阅读量: 625

数据分析师 Python数据分析

如何检查是否所有元素元素都填充在Python中

扫码加入数据分析学习群

我正在使用数组或列表在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))

17.1228 2 0 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子