单选题
适中
#15932
小明正在编写一个程序,用于处理一个班级学生的成绩。他需要筛选出所有及格的成绩(60分及以上)。以下是他的代码: scores = [58, 72, 85, 64…
小明正在编写一个程序,用于处理一个班级学生的成绩。他需要筛选出所有及格的成绩(60分及以上)。以下是他的代码:
scores = [58, 72, 85, 64, 43, 90, 56]
JiGe = [score for score in scores if score >= 60]
print(JiGe)
请问这段代码的输出结果是?( )
答案与解析
正确答案:D
解析
列表推导式[score for score in scores if score >= 60]会遍历scores列表,并筛选出所有大于或等于60的分数。因此,输出结果为[72, 85, 64, 90]。