设计一个Course(课程)类,该类中包括number(编号)、name(名字)、teacher(任课老师)、location(上课地点),其中上课地点是私有属性,包括构造方法。设计代码。三种方法自取

class Project:
    def __init__(self):
        self .number = 1
        self .name = "python"
        self .teacher = "Mr.wang"
        self .__place = "DingTalk"

    def show(self):
        print("""
                 课程编号:%d
                 课程名称:%s
                 任课教师:%s
                 上课地点:%s
                 """ %(self .number, self .name, self.teacher, self.__place)
              )
project = Project()
print(project.show())
class Course:
    def __init__(self, number, name, teacher, place):
        self.number = number
        self.name = name
        self.teacher = teacher
        self.__place = place

    def __str__(self):
        return '课程编号:%d\n课程名称:%s\n任课教师:%s\n上课地点:%s\n'%(self.number, self.name, self.teacher, self.__place)

myclass = Course(1, "python", "王老师", "线上")
print(myclass)
class Course:
    def __init__(self,number,name,teacher,place):
        self.number = number
        self.name = name
        self.teacher = teacher
        self.__place = place

    def show(self):
        return '课程编号{}、课程名称{}、任课教师{}、上课地点{}'.format(self.number,self.name,self.teacher,self.__place)

a = Course (1,'python','王老师','学校')
b = Course (2, "math", "张老师", "qq")
c = Course (3, "English","靳老师", "DingTalk")
print(a.show() )
print(b.show() )
print(c.show() )

你可能感兴趣的:(python,开发语言)