0.定義一個學生類醋旦。有屬性:姓名缺前、年齡、成績(語文著摔,數(shù)學,英語)[每課成績的類型為整數(shù)]
方法:
a. 獲取學生的姓名:getname()
b. 獲取學生的年齡:getage()
c. 返回3門科目中最高的分數(shù)定续。get_course()
class Student:
def __init__(self, name, age, score):
self.name = name
self.age = age
self.score = score
def getname(self):
print('學生姓名:%s' % self.name)
def getage(self):
print('學生年齡:%s' % self.age)
def main():
stu1 = Student('王月?熙', 12, score=[95,99,98])
stu1.getname()
stu1.getage()
print(max(stu1.score))
1.建立一個汽車類Auto谍咆,包括輪胎個數(shù),汽車顏色私股,車身重量摹察,速度等成員變量,并通過不同的構造方法創(chuàng)建實例倡鲸。
至少要求 汽車能夠加速 減速 停車供嚎。
再定義一個小汽車類CarAuto 繼承Auto 并添加空調、CD等成員變量 覆蓋加速 減速的方法
class Auto:
def __init__(self, tire, color, weight, speed):
self.tire = tire
self.color = color
self.weight = weight
self.speed = speed
def speed_up2(self):
print('對象方法峭状!現(xiàn)在是加速克滴!')
def speed_cut2(self):
print('對象方法!現(xiàn)在是減速优床!')
def stop2(self):
print('對象方法劝赔!現(xiàn)在是停車!')
@staticmethod
def speed_up():
print('靜態(tài)方法羔巢!現(xiàn)在是加速怀酷!')
@staticmethod
def speed_cut():
print('靜態(tài)方法!現(xiàn)在是減速烟勋!')
@staticmethod
def stop():
print('靜態(tài)方法蚌卤!現(xiàn)在是停車!')
@classmethod
def speed_up1(cls):
print('類方法幽钢!現(xiàn)在是加速歉备!')
@classmethod
def speed_cut1(cls):
print('類方法!現(xiàn)在是減速匪燕!')
@classmethod
def stop1(cls):
print('類方法蕾羊!現(xiàn)在是停車!')
class CarAuto(Auto):
def __init__(self, tire, color, weight, speed, meidi, CD):
super().__init__(tire, color, weight, speed)
self.meidi = meidi
self.CD = CD
def mei_di(self):
print('空調帽驯!')
def C_D(self):
print('CD')
def main():
car1 = Auto(4, '白色', '500kg', '120km/h')
car1.speed_up2()
car1.speed_cut2()
car1.stop2()
Auto.speed_cut()
Auto.speed_up()
Auto.stop()
Auto.speed_cut1()
Auto.speed_up1()
Auto.stop1()
c1 = CarAuto(4, '白色', '500kg', '100km/h', 'haier', 'zjl')
c1.mei_di()
c1.C_D()