首页 > 编程语言 > 详细

Python做一个生成txt的学生成绩录入

时间:2020-09-15 10:44:37      阅读:109      评论:0      收藏:0      [点我收藏+]

本人小白一枚

 1 #/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 # @Time : 2020/7/25 0:11 
 4 # @Author : Zero, 纷飞的花火丶
 5 # @File : 学生管理系统.py 
 6 # @Software: PyCharm
 7 
 8 ls = [排名\t姓名\t语文\t数学\t英语\t总分\n]
 9 score = []
10 n = 3
11 print("欢迎来到学生录入系统")
12 
13 # 学生成绩填入
14 def filewrite():
15     names = input("请输入姓名:")
16     scoreCN = input("请输入语文成绩:")
17     scoreMH = input("请输入数学成绩:")
18     scoreEN = input("请输入英语成绩:")
19     ls.append(f"{names}\t{scoreCN}\t{scoreMH}\t{scoreEN}\n")
20 
21 filewrite()
22 
23 while True:
24     ct = input("是否继续录入(y/n):")
25     if ct in [Yes, YES, Y, y]:
26         filewrite()
27 
28     elif ct in [No, NO, N, n]:
29         for i in ls:
30             score.append(i.split())
31         # 计算各个学生的总分并将总分加入列表
32         for h in score[1:]:
33             zf = int(h[1]) + int(h[2]) + int(h[3])
34             h.append(str(zf))
35 
36         # 按总分进行排序
37         score.sort(key = lambda x:x[4], reverse=True)
38 
39         # 给学生加入排名
40         for i in range(1, len(score[1:])+1):
41             score[i].insert(0, i)
42 
43         # 把数据写入记事本里
44         with open(r"E:\Build\学生成绩.txt",x) as file:
45             for h in score:
46                 for i in h:
47                     file.write(str(i) + "\t")
48                 file.write("\n")
49         print("录入完毕")
50         break
51 
52     # 用户乱输入三次就退出
53     else:
54         n -= 1
55         if n == 0:
56             break
57         print(f"输入不合法,你还有{n}次机会,请重新输入")
58         continue

 

Python做一个生成txt的学生成绩录入

原文:https://www.cnblogs.com/ZeroZN/p/13671390.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!