首页 > 解决方案 > 记住上次展示作业的3个学生

问题描述

上次展示作业的3名学生。每次运行此程序时,它应该选择一组新的 3 名学生。

标签: python-3.x

解决方案


假设给定学生的卷号

students_roll_number = [1,2,3,4,5,6,7,8,9,10,11]

students_homework_showed = [3,4,5]

让尚未展示作业的学生

students_homework_pending = [students_roll_number[i] for i in  range(len(students_roll_number)) if students_roll_number[i] not in students_homework_showed]

输出是

students_homework_pending = [1, 2, 6, 7, 8, 9, 10, 11]

现在我们从待定列表中挑选 3 名学生

students_to_check = []
for i in range(3): 
    students_homework_showed.append(students_homework_pending[i])
    students_to_check.append(students_homework_pending[i])

新学生可供选择

print("chosen student is : ", students_to_check)

推荐阅读