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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值