首页 > 代码库 > 对象-3.py

对象-3.py

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #cbcbcb } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #00b400 } span.s1 { text-decoration: underline } span.s2 { color: #0433ff } span.s3 { color: #941100 } span.s4 { color: #000000 } span.s5 { color: #00b400 } span.s6 { text-decoration: underline; color: #00b400 }</style>

#coding: utf-8

class Member(object):

    member_nums = 0

    def __init__(self,name,age,sex):

        self.name = name

        self.age = age

        self.sex = sex

        self.enroll()

        

    def enroll(self):

        Member.member_nums += 1

        print("THE [%s] School Member  [%s] is enrolled!" %(Member.member_nums,self.name))

        

        

    def tell(self):

        print ("hello my name is [%s]" %self.name)

    

    

class Teacher(Member):

    def __init__(self,name,age,sex,couse,salary):

        super(Teacher,self).__init__(name,age,sex)

        self.couse = couse

    

    def teaching(self):

        print ("Teacher [%s] is teaching [%s]" %(self.name,self.couse))

        

class Student(Member):   

    def __init__(self,name,age,sex,couse,tuition):

        super(Student,self).__init__(name,age,sex)

        self.couse = couse

        self.tuition = tuition

    def pay_tuition(self):

        print (" fuck ,student [%s] paying tuition [%s]" %(self.name,self.tuition))

        

        

t1 = Teacher("alex",22,‘f‘,"PY",1000)

t2 = Teacher("box",25,"f","N/A",100) 

s1 = Student("Sanjiang",24,"F","java",15000)  

s2 = Student("jay",24,"m","go",14000)  

t1.tell()

s1.tell() 

t1.teaching()   

s1.pay_tuition()

对象-3.py