已知成绩等级划分为{“A”:[90~100],"B":[80~89],"c":[60~79],"D":[0~59]}
1、随机生成20个整数,范围0-100
2、按等级归类,输出成绩等级列表字典如下:
{'A': [96, 96, 97, 97, 100, 100], 'B': [86], 'C': [71, 73, 66, 67], 'D': [9, 44, 54, 44, 37, 6, 29, 23, 39, 31, 23, 17]}
答案

import random
list = []
for i in range(20):list.append(random.randint(0,100))print(list)
dict = {"A":[],"B":[],"C":[],"D":[]}
for j in list:if j >=90:dict["A"].append(j)if 80 <= j <90:dict["B"].append(j)if j >=90:dict["A"].append(j)if 60 <= j <79:dict["C"].append(j)if j <60:dict["D"].append(j)
print(dict)