# Author : Kelvin
# Date : 2019/1/15 20:44 """
学校与老师关联
课程与老师和学校关联
""" class School():
def __init__(self, name, profession):
self.name = name
self.profession=profession class Teacher():
def __init__(self, name, age, gender, school):
self.name = name
self.age = age
self.gender = gender
self.school=school class Course():
def __init__(self, name, time, school, teacher):
self.name = name
self.time = time
self.school = school
self.teacher = teacher s1 = School("大庆师范学院", "计算机专业")
s2 = School("大庆师范学院", "生物工程专业")
s3 = School("大庆师范学院", "外国语专业") t1 = Teacher("kelvin", 22, "male", s1)
t2 = Teacher("alex", 23, "male", s3)
t3 = Teacher("jam", 25, "female", s2) msg1="""
学校选项:
1:"大庆师范学院", "计算机专业"
2:"大庆师范学院", "生物工程专业"
3:"大庆师范学院", "外国语专业"
"""
msg2="""
教师选项:
1:"kelvin", 22, "male", "大庆师范学院", "计算机专业"
2:"alex", 23, "male", "大庆师范学院", "外国语专业"
3:"jam", 25, "female","大庆师范学院", "生物工程专业"
"""
while True:
print(msg1)
choice1 = input("请选择学校专业:")
s = {
"": s1,
"": s2,
"": s3
}
if choice1 in s:
sx = s[choice1]
else:
print("专业选择异常,请重试!")
break print(msg2)
choice2 = input("请选择老师:")
t = {
"": t1,
"": t2,
"": t3
}
if choice2 in t:
tx = t[choice2]
else:
print("教师选择异常,请重试!")
break
course_name = input("请输入课程名:")
course_time = input("请输入课程时长:")
new_course = Course(course_name, course_time, sx, tx)
print("选课成功! [%s]课程所属的学校是[%s]专业是[%s] 老师名字[%s]年龄[%s]性别[%s]所属学校[%s]专业[%s] 课程时长:[%s]" % (
new_course.name, new_course.school.name, new_course.school.profession, new_course.teacher.name,
new_course.teacher.age, new_course.teacher.gender, new_course.teacher.school.name,new_course.teacher.school.profession,new_course.time))
break