第50天python学习组合————————运行例子失败待修改

# 组合: 组合就是把类和类链接起来,
#实例操作;学校 老师 课程建立关系
class School:
def __init__(self,name,addr):
self.name=name,
self.addr=addr

class Teach:
def __init__(self,name,zhiji):
self.ID=name ,
self.zhiji=zhiji

class Kecheng:
def __init__(self,name,keshi,jiage,school,teach):
self.keshi=keshi,
self.neirong=jiage,
self.name=name,
self.school=school,
self.teach=teach

s1= School("清华","北京")
s2= School("清华","北京1")
s3= School("清华","北京3")
msg="""
1 清华 北京校区
2 清华 北京1校区
3 清华 北京2校区
"""
menu={
"1":s1,
"2":s2,
"3":s3
}
choice=input("选择学校>>>>:")
school=menu[choice]#实例化学校

name=input("课程名>>>>:")
keshi=input("课时>>>>:")
jiage=input("价格>>>>:")


t1= Teach("张三","40000")
t2= Teach("李四","7000")
t3= Teach("李四","7000")
laoshi={
"1":t1,
"2":t2,
"3":t3
}

choice1=input("选择老师>>>>:")
teach=menu[choice1]#实例化老师

#课程和学校关系
new_kecheng=Kecheng(name,keshi,jiage,school,teach)
print("课程【%s】属于【%s】学校"%(new_kecheng.name,new_kecheng.school.name))

#老师关联学校 课时

new_kecheng1=Kecheng(name,keshi,jiage,school,teach)
print("【%s】老师在【%s】学校上【%s】课程"%(new_kecheng1.teach.ID,new_kecheng1.school.name,new_kecheng1.name))

posted on 2019-10-12 22:46  坚持是多么伟大的事情  阅读(151)  评论(0编辑  收藏  举报