class School:
def __init__(self,name,address):
self.name=name
self.address=address
def zhao_sheng(self):
print('%s正在招生'%self.name)
class Course:
def __init__(self,name,price,period,school):
self.name=name
self.price=price
self.period=period
self.school=school
s1=School('oldboy','北京')
s2=School('oldboy','南京')
s3=School('oldboy','东京')
c1=Course('Linux',10,'1h',s1)
# print(c1.__dict__)
# print(c1.school.name)
msg='''
1 老男孩 北京校区
2 老男孩 南京校区
3 老男孩 东京校区
'''
while True:
print(msg)
menu={
'1':s1,
'2':s2,
'3':s3,
}
choice=input('选择学校>>')
school_obj=menu[choice]
name=input('课程名>>:')
price= input('费用>>:')
period = input('周期>>:')
new_couese=Course(name,price,period,school_obj)
print('课程%s属于%s学校'%(new_couese.name,new_couese.school.name))
主要看思考怎么关联的