简单模拟选课系统(类的组合)

class School:
    def __init__(self,name,addr):
        self.name=name
        self.addr=addr
    def tell_school(self):
        print('你选择的是%s校区的%s'%(self.addr,self.name))
class Course:
    def __init__(self,name,period,price,school):
        self.name=name
        self.period=period
        self.price=price
        self.school=school
    def tell_inform(self):
        print('你选择的是为期%s周的%s课程,费用为%s元'%(self.period,self.name,self.price))
class Teacher:
    def __init__(self,name,course,school):
        self.name=name
        self.course=course
        self.school=school
    def tell(self):
        print('你选择的是%s学校%s老师教的为期%s周的%s课程'%(self.school.name,self.name,self.course.period,self.course.name))


s1=School('新东方','北京')
s2=School('新东方','南京')
s3=School('新东方','河北')
sch={     '1':s1,
          '2':s2,
          '3':s3}
sch1='''
       1.北京
       2.南京
       3.河北'''
cour={     '1':{'Python':[2000,20]},
           '2':{'Linux':[1500,15]}}

cour1='''
        1.Python
        2.Linux'''
tec={      '1':'Alex',
           '2':'Bart',
           '3':'Lisa'}
tec1=''' 
        1.Alex
        2.Bart
        3.Lisa
        '''
chosen=True
while chosen:
    print(sch1)
    s=input('请选择学校与校区:')
    sch[s].tell_school()
    print(cour1)
    c=input('请选择课程:')
    co=Course(list(cour[c].keys())[0],list((cour[c].values()))[0][1],list((cour[c].values()))[0][0],sch[s])
    co.tell_inform()
    print(tec1)
    t=input('请选择老师:')
    te=Teacher(tec[t],co,sch[s])
    te.tell()
    chosen=False


你可能感兴趣的:(python基础)