Python实现简易版选课系统
需求:一、创建学生类
# 创建学生类
import random
class Student:
def __init__(self,num,name,address,course_lst=None):
self.num=num
self.name=name
self.address=address
if course_lst:
self.cous_lst=cous_lst
else:
self.cous_lst=[]
def look(self): #查看学生所有的课程信息
print("%s学生的选课信息:"%self.name)#输出信息提示
for el in self.cous_lst:
print(el.name,end="")
print()
def adds(self,s):#学生添加课程
self.cous_lst.append(s)二、创建课程类
# 创建课程类
class Course:
def __init__(self,num,name,teacher=None):
self.num = num
self.name = name
self.teacher=teacher
def look(self):#查看课程信息
return "课程编号: %s ,课程名称: %s ,课程老师: %s " %(self.num,self.name,self.teacher)
def sett(self,t):#给课程添加老师
self.teacher=t三、创建教师类
# 创建教师类
class Teacher:
def __init__(self,num,name,phone):
self.num = num
self.name = name
self.phone=phone四、创建6个老师
# 创建6个老师
t1=Teacher("N01","寒冰",10086)
t2=Teacher("N02","疾风剑豪",10387)
t3=Teacher("N03","瞎子",10088)
t4=Teacher("N04","机器人",10536)
t5=Teacher("N05","德玛西亚",24550)
t6=Teacher("N06","武器",10089)五、创建6门课程
# 创建6门课程
c1=Course("KS01","上单")
c2=Course("KS02","中单")
c3=Course("KS03","下路AD")
c4=Course("KS04","辅助")
c5=Course("KS05","打野")
c6=Course("KS06","日中天")
c_lst=六、给课程安排老师
# 给课程安排老师
c1.sett(t6)
c2.sett(t2)
c3.sett(t1)
c4.sett(t4)
c5.sett(t3)
c6.sett(t5)七、定义随机数函数
# 创建随机产生3个不重复的数字#学习中遇到问题没人解答?小编创建了一个Python学习交流群:153708845import randomdef rand(): lst=[] while len(lst)
页:
[1]