随机生成10名学生姓名(包括自己)和五科成绩,将数据存入*.csv,读取保存的*.csv文本数据计算每个学生总分和平均分,并存入*.csv文本;打印总分排名前三学生信息;查找10学生各科最高最低分、中位分、平均分。
(笔记模板由python脚本于2023年11月13日 12:36:51创建,本篇笔记适合熟悉python基本数据类型的coder翻阅)
-  Python 官网:https://www.python.org/ 
-  Free:大咖免费“圣经”教程《 python 完全自学教程》,不仅仅是基础那么简单…… 
 地址:https://lqpybook.readthedocs.io/
  自学并不是什么神秘的东西,一个人一辈子自学的时间总是比在学校学习的时间长,没有老师的时候总是比有老师的时候多。
             —— 华罗庚
- My CSDN主页、My HOT博、My Python 学习个人备忘录
- 好文力荐、 老齐教室
 
 
本文质量分:
本文地址: https://blog.csdn.net/m0_57158496/
CSDN质量分查询入口:http://www.csdn.net/qc
- ◆ 学生五科成绩统计
- 1、题目描述
- 2、算法解析
- 2.1 10名学生成绩数据生成
- 2.2 总分、平均分文本*.csv
- 2.3 前三名确定
- 2.4 各科成绩统计
 
- 3、完整源码
 
◆ 学生五科成绩统计
1、题目描述
- 题目描述截屏图片
  
【题目来源于 CSDN 问答社区提问“学生五科成绩统计”】
2、算法解析
- 代码运行效果截屏图片(部分)
  
编辑中……
2.1 10名学生成绩数据生成
编辑中……
python代码
#!/sur/bin/nve python
# coding: utf-8
from random import choices
from random import randint
firstNames = list('赵钱孙李周武郑王刘祖') + ['东郭', '南郭', '东方', '上官']
lateNames = list('芳全平苹明远员') + ['精灵_cq', '明远', '文远', '太平', '冲之']
names = [''.join(choices(firstNames) + choices(lateNames)) for i in range(10)] # 随机生成10个姓名。
if '梦幻精灵_cq' not in names: # 如果没随机到自己姓名,pop最后一个,append自己。
    names.pop()
    names.append('梦幻精灵_cq')
while 1:
    classes = input('\n五门课程名称用空格分隔(如:语文 数学 ... 化学):\n\n输入:').strip()
    
    if len(classes.split()) == 5:
        break
    else:
        print(f"{' 输入错误!':~^35}")
scores = {name: ' '.join(map(str,[randint(0, 100) for i in range(5)])) for name in names}
stuId = '20231112035' # 我的学号。
filename = f'/sdcard/Documents/csdn/temp/{stuId}_scores.csv'
with open(filename, 'w') as f:
    print('姓名 ' + classes, file=f, end='') # 写表头,不换行。
    
    for k,v in scores.items():
        f.write(f"\n{k} {v}") # 换行打印输出成绩到csv文本。
cosesCsv = open(filename).read()
print(f"\n成绩列表:\n{cosesCsv}")
2.2 总分、平均分文本*.csv
  编辑中……
#!/sur/bin/nve python
# coding: utf-8
from random import choices
from random import randint
from random import seed
seed(20231113) # 设置随机数种子,让每次运算程序产生的随机数都是一样,改变种子参数改变输出。
firstNames = list('赵钱孙李周武郑王刘祖') + ['东郭', '南郭', '东方', '上官']
lateNames = list('芳全平苹明远员') + ['精灵_cq', '明远', '文远', '太平', '冲之']
names = [''.join(choices(firstNames) + choices(lateNames)) for i in range(10)] # 随机生成10个姓名。
if '梦幻精灵_cq' not in names: # 如果没随机到自己姓名,pop最后一个,append自己。
    names.pop()
    names.append('梦幻精灵_cq')
while 1:
    #classes = input('\n五门课程名称用空格分隔(如:语文 数学 ... 化学):\n\n输入:').strip()
    classes = '语文 数学 英语 理化 政史'
    
    if len(classes.split()) == 5:
        break
    else:
        print(f"{' 输入错误!':~^35}")
scores = {name: ' '.join(map(str,[randint(0, 100) for i in range(5)])) for name in names}
stuId = '20231112035' # 我的学号。
filename = f'/sdcard/Documents/csdn/temp/{stuId}_scores.csv'
with open(filename, 'w') as f:
    print('姓名 ' + classes, file=f, end='') # 写表头,不换行。
    
    for k,v in scores.items():
        f.write(f"\n{k} {v}") # 换行打印输出成绩到csv文本。
scoresCsv = open(filename).read()
print(f"\n成绩列表:\n{scoresCsv}")
filename2 = f'/sdcard/Documents/csdn/temp/ave_scores.csv'
lastHead = scoresCsv.split('\n')[0]
with open(filename2, 'w') as f:
    print(f"{lastHead} 总分 平均分", file=f, end='') # 写表头,不换行。
    
    for i in scoresCsv.split('\n')[1:]: # 遍历csv成绩文本行,切片去除第一行字段。
        count = sum(map(int, i.split()[1:])) # # 切片分离五科成绩,并计算总分。
        f.write(f"\n{i} {count} {count/5:.2f}") # 换行打印输出成绩到csv文本。
print(f"\n成绩列表(总分、平均分):\n{open(filename2).read()}")
2.3 前三名确定
  编辑中……
- 代码运行效果截屏图片
代码编撰中……
2.4 各科成绩统计
  编辑中……
- 代码运行效果截屏图片
代码编撰中……
3、完整源码
(源码较长,点此跳过源码)
待贴……
上一篇: 幸运素数(从键盘输入一个区间,程序判定输出区间的所有幸运素数)
下一篇:
我的HOT博:
  本次共计收集 246 篇博文笔记信息,总阅读量 40.46w,平均阅读量 1644。已生成 16 篇阅读量不小于 4000 的博文笔记索引链接。数据采集于 2023-10-12 05:41:03 完成,用时 4 分 41.10 秒。
- ChatGPT国内镜像站初体验:聊天、Python代码生成等
 ( 59262 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/129035387
 点赞:126 踩 :0 收藏:798 打赏:0 评论:71
 本篇博文笔记于 2023-02-14 23:46:33 首发,最晚于 2023-07-03 05:50:55 修改。
- 让QQ群昵称色变的神奇代码
 ( 58086 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/122566500
 点赞:24 踩 :0 收藏:83 打赏:0 评论:17
 本篇博文笔记于 2022-01-18 19:15:08 首发,最晚于 2022-01-20 07:56:47 修改。
- pandas 数据类型之 DataFrame
 ( 9173 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/124525814
 点赞:6 踩 :0 收藏:31 打赏:0 评论:0
 本篇博文笔记于 2022-05-01 13:20:17 首发,最晚于 2022-05-08 08:46:13 修改。
- 个人信息提取(字符串)
 ( 7215 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/124244618
 点赞:1 踩 :0 收藏:13 打赏:0 评论:0
 本篇博文笔记于 2022-04-18 11:07:12 首发,最晚于 2022-04-20 13:17:54 修改。
- Python列表(list)反序(降序)的7种实现方式
 ( 7161 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/128271700
 点赞:5 踩 :0 收藏:22 打赏:0 评论:8
 本篇博文笔记于 2022-12-11 23:54:15 首发,最晚于 2023-03-20 18:13:55 修改。
- 罗马数字转换器|罗马数字生成器
 ( 7035 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/122592047
 点赞:0 踩 :0 收藏:1 打赏:0 评论:0
 本篇博文笔记于 2022-01-19 23:26:42 首发,最晚于 2022-01-21 18:37:46 修改。
- Python字符串居中显示
 ( 6966 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/122163023
 点赞:1 踩 :0 收藏:7 打赏:0 评论:1
 本篇博文笔记
- 斐波那契数列的递归实现和for实现
 ( 5523 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/122355295
 点赞:4 踩 :0 收藏:2 打赏:0 评论:8
 本篇博文笔记
- python清屏
 ( 5108 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/120762101
 点赞:0 踩 :0 收藏:8 打赏:0 评论:0
 本篇博文笔记
- 练习:字符串统计(坑:f‘string‘报错)
 ( 5103 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/121723096
 点赞:0 踩 :0 收藏:1 打赏:0 评论:0
 本篇博文笔记
- 回车符、换行符和回车换行符
 ( 5093 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/123109488
 点赞:1 踩 :0 收藏:2 打赏:0 评论:0
 本篇博文笔记于 2022-02-24 13:10:02 首发,最晚于 2022-02-25 20:07:40 修改。
- 练习:尼姆游戏(聪明版/傻瓜式•人机对战)
 ( 4943 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/121645399
 点赞:14 踩 :0 收藏:42 打赏:0 评论:0
 本篇博文笔记
- 密码强度检测器
 ( 4323 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/121739694
 点赞:1 踩 :0 收藏:4 打赏:0 评论:0
 本篇博文笔记于 2021-12-06 09:08:25 首发,最晚于 2022-11-27 09:39:39 修改。
- 练习:生成100个随机正整数
 ( 4274 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/122558220
 点赞:1 踩 :0 收藏:6 打赏:0 评论:0
 本篇博文笔记于 2022-01-18 13:31:36 首发,最晚于 2022-01-20 07:58:12 修改。
- 我的 Python.color() (Python 色彩打印控制)
 ( 4159 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/123194259
 点赞:2 踩 :0 收藏:8 打赏:0 评论:0
 本篇博文笔记于 2022-02-28 22:46:21 首发,最晚于 2022-03-03 10:30:03 修改。
- 罗马数字转换器(用罗马数字构造元素的值取模实现)
 ( 4149 阅读)
 博文地址:https://blog.csdn.net/m0_57158496/article/details/122608526
 点赞:0 踩 :0 收藏:0 打赏:0 评论:0
 本篇博文笔记于 2022-01-20 19:38:12 首发,最晚于 2022-01-21 18:32:02 修改。
 
 
精品文章:
- 好文力荐:齐伟书稿 《python 完全自学教程》 Free连载(已完稿并集结成书,还有PDF版本百度网盘永久分享,点击跳转免费🆓下载。)
- OPP三大特性:封装中的property
- 通过内置对象理解python'
- 正则表达式
- python中“*”的作用
- Python 完全自学手册
- 海象运算符
- Python中的 `!=`与`is not`不同
- 学习编程的正确方法
来源:老齐教室
◆ Python 入门指南【Python 3.6.3】
好文力荐:
- 全栈领域优质创作者——[寒佬](还是国内某高校学生)博文“非技术文—关于英语和如何正确的提问”,“英语”和“会提问”是编程学习的两大利器。
- 【8大编程语言的适用领域】先别着急选语言学编程,先看它们能干嘛
- 靠谱程序员的好习惯
- 大佬帅地的优质好文“函数功能、结束条件、函数等价式”三大要素让您认清递归
CSDN实用技巧博文:
- 8个好用到爆的Python实用技巧
- python忽略警告
- Python代码编写规范
- Python的docstring规范(说明文档的规范写法)



















