欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

基于python 成绩转换工具

程序员文章站 2024-03-18 20:58:52
...

09.py


# 1、系统首先需要将学生的学号,姓名和成绩等信息录入
# 2、录入成绩完成后,系统自动判断成绩的等级
# 3、0-59为E级,60-69为D级,70-79为C级,80-89为B级,90-100为A级
# 4、最后,将学生学号,姓名,成绩等级显示出来
# 5、统计不同等级的百分比

import pandas as pd

class Stu:
    def __init__(self,no,name,score):
        self.no = no
        self.name = name
        self.score = score

    def get_rank(self):
        rank = 'E'
        if self.score>59 and self.score<70:
            rank = 'D'
        elif self.score>69 and self.score<80:
            rank = 'C'
        elif self.score > 79 and self.score < 90:
            rank = 'B'
        elif self.score > 89 and self.score < 101:
            rank = 'A'
        else:
            pass
        return rank

def to_dataframe(stus):
    names = []
    nos = []
    scs = []
    djs = []
    for a in stus:
        nos.append(a.no)
        names.append(a.name)
        scs.append(a.score)
        djs.append(a.get_rank())
    dire = {"学号": nos, "姓名": names, "成绩": scs, "等级": djs}
    p = pd.DataFrame(dire)
    return p


if __name__ == '__main__':
    f = True
    stu_list = []
    while f:
        no = input("请输入学号:")
        name = input("请输入姓名:")
        sc = int(input("请输入成绩:"))
        s = Stu(no, name, sc)
        stu_list.append(s)
        a = input("是否继续输入(n:结束)")
        if a == 'n':
            f = False

    print("-----------------学生成绩----------------------")
    print(to_dataframe(stu_list))
    print("---------------------------------------------")

 

相关标签: python 成绩转换