本文实例为大家分享了python随机打印一张成绩排名表的具体代码,供大家参考,具体内容如下
有五个学生,姓名自行添加,有三门考试:语文、数学、英语,随机为这10个同学生成分数【50,100】,需求:打印一张成绩排名表。
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import random import string list_index = [ "名次" , "学号" , "姓名" , "语文" , "数学" , "英语" , "总分" , "均分" ] #定义字段名 list_name = [ "赵云" , "关羽" , "张飞" , "黄忠" , "马超" , "张三" , "李四" , "李五" , "赵四" , "苏苏" ] #定义名字 list_num = [] dict_num = {} for i in range ( 0 , len (list_name)): T = [] for j in range ( 0 , 3 ): T.append(random.randint( 50 , 100 )) T.append( sum (T)) T.append(T[ - 1 ] / len (T)) T.insert( 0 ,list_name[i]) T.insert( 0 , 2000 + i) list_num.append( list (T)) T.clear() list_num = sorted (list_num,key = ( lambda x:x[ 6 ])) list_num.reverse() for i in range ( 0 , len (list_name)): dict_num[ str (i + 1 )] = list_num[i] print ( "成绩统计表" .center( 54 , "#" )) print ( str (list_index[ 0 ]).center( 6 ),end = " " ) for j in range ( 1 , 8 ): #循环输出所有字段名 print (list_index[j].center( 5 ),end = " " ) print () print ( "=" * 57 ) for i,j in dict_num.items(): print ( str (i).center( 8 ),end = " " ) for x in j: print ( str (x).center( 6 ),end = " " ) print () print ( "=" * 57 ) |
运行几次的结果:
关于python成绩管理系统的内容可以查看这篇专题。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/Sconnie/article/details/113307263