day24-job-object-oriented-class

department

# 选课系统项目中涉及到诸多数据与功能,要求引入面向对象的思想对其进行高度整合
# 1、学校数据与功能整合
# 2、课程数据与功能进行整合
# 3、学生数据与功能进行整合
# 4、讲师数据与功能进行整合
# 5、班级数据与功能进行整合
# ps:不会写的同学,可以先用普通的方式,先把数据与功能都给写好,再考虑基于面向对象的思想进行整合
# 数据部分:
#      校区的名字:如"老男孩上海校区"
#      校区的地址:如"上海虹桥"
#
#      班级名字
#      班级所在校区
#
#      学生的学校
#      学生的姓名
#      学生的年龄
#      学号
#      学生的性别
#
#      课程名字
#      课程周期
#      课程价格
#
#      老师的名字
#      老师的年龄
#      老师的薪资
#      老师的等级

# 功能部分:
#      校区创建完毕后,可以为每个校区创建班级
#
#      班级创建完毕后,可以为每个班级创建课程
#
#      学生创建完毕后,学生可以选择班级
#
#      老师创建完毕后,可以为学生打分
course_list = ['python', 'linux']


class Student:
    school = '老男孩上海校区'
    Address = '上海虹桥'
    course = None

    def __init__(self, name1, age1, student_id1, gender1):
        self.name = name1
        self.age = age1
        self.student_id = student_id1
        self.gender = gender1

    def choose(self):
        print(f'学生{self.name}正在选课')
        for index, i in enumerate(course_list):
            print(index, i)
        choice = input('请选课:').strip()
        if not choice.isdigit():
            print('请输入正确编号')
        choice = int(choice)
        if choice not in range(len(course_list)):
            print('请输入正确编号')
        course = course_list[choice]
        print('已成功选课', course)

    def info(self):
        print(f'{self.name}{self.student_id}')


student1 = Student('egon', '84', 'dsb', 'unknown')
student2 = Student('sailan', '20', '101', 'male')
student3 = Student('tank', '30', '9527', 'male')

student3.choose()


student_dic = {
    
    'sailan': None, '张三': None}


class Teacher:
    school = '老男孩上海校区'
    Address = '上海虹桥'

    def __init__(self, name1, age1, salary1, lv1):
        self.name = name1
        self.age = age1
        self.salary = salary1
        self.lv = lv1

    def choose(self):
        print(f'老师{self.name}正在为学生打分')
        for i in student_dic:
            print(i)
        choice = input('请输入学生姓名:').strip()
        if choice in student_dic:
            choice1 = input('请输入打的分数:').strip()
            student_dic[choice] = choice1
            print(student_dic)
        else:
            print('请输入正确的类型')


teacher1 = Teacher('egon', '84', '1', '-1')
teacher2 = Teacher('lxx', '20', '1', '1')
teacher3 = Teacher('tank', '30', '1', '1')

teacher1.choose()

Guess you like

Origin blog.csdn.net/msmso/article/details/107788444