Python 学生成绩管理体系

import os
class Student:                       #定义一个学生类
    def __init__(self):
        self.name = ''
        self.ID = ''
        self.score1 = 0
        self.score2 = 0
        self.score3 = 0
        self.sum = 0
    def sumscore(self):              #计算总分
        self.sum=self.score1 + self.score2 +self.score3
#----------------
def searchByID(stulist,ID):          #按学号查找看是否学号已经存在
    for item in stulist:
        if item.ID == ID:
            return True
def Add(stulist,stu):                #添加一个学生信息
    if searchByID(stulist,stu.ID) == True:
        print('学号已存在!')
        return False
    stulist.append(stu)
    print(stu.name,stu.ID,stu.score1,stu.score2,stu.score3,stu.sum)
    print('是否要保存学生信息?')
    nChoose = input('Choose Y/N')
    if nChoose == 'Y' or nChoose == 'y':
        file_object = open('students.txt','a')
        file_object.write(stu.ID)
        file_object.write('')
        file_object.write(stu.name)
        file_object.write('')
        file_object.write(str(stu.score1))
        file_object.write('')
        file_object.write(str(stu.score2))
        file_object.write('')
        file_object.write(str(stu.score3))
        file_object.write('')
        file_object.write(str(stu.sum))
        file_object.write('\n')
        fil

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值