组合练习

class Course:
    def __init__(self, cname, period, fee):
        self.cname = cname
        self.period =period
        self.fee = fee

    def get_course(self):
        print('The course name is %s, period is %s, the fee is %s '%(self.cname,self.period, self.fee))

class Birthday:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

    def get_birthday(self):
        print('The birthday is %s %s %s'%(self.year, self.month, self.day))

class People:
    country = 'China'
    def __init__(self, name, age):
        self.name = name
        self.age = age
        self.courses = []

    def tell_info(self):
        print('Name is %s, the age is %s'%(self.name, self.age))

class People1(People):
    def __init__(self, name, age, sex, hobby):
        super().__init__(name, age)
        self.sex = sex
        self.hobby = hobby
        self.courses = []


    def tell_info(self):
        super().tell_info()
        print('the gender is %s, the hobby is %s' % (self.sex, self.hobby))

    def show_course_info(self):
        print(('%s course info is following'% self.name).center(45,'='))
        for course_obj in self.courses:
            course_obj.get_course()

p = People1('Raimond', 18, 'male', 'reading')
python = Course('python', '3weeks', '2000')
mysql = Course('mysql', '1weeks', '500')
web = Course('web', '5weeks', '5000')
p.courses.extend([python, mysql,web])
p.show_course_info()


C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe “C:/Users/user/PycharmProjects/hellow python/test.py”
=Raimond course info is following
The course name is python, period is 3weeks, the fee is 2000
The course name is mysql, period is 1weeks, the fee is 500
The course name is web, period is 5weeks, the fee is 5000

Process finished with exit code 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值