2020.1.6

101.
class Car():
    def __init__(self , make , model , year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0
    
    def get_descriptive_name(self):
        long_name = str(self.year) + " " + self.make + " " + self.model
        return long_name.title()
    
    def read_odometer(self):
        print("This car has " + str(self. odometer_reading) + " miles on it.")
        
    def update_odometer(self , mileage):
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")
            
    def increment_odometer(self , miles):
        self.odometer_reading += miles

my_used_car = Car('subaru' , 'ourback' , '2013')
print(my_used_car.get_descriptive_name())

my_used_car.read_odometer()

my_used_car.odometer_reading = 40
my_used_car.read_odometer()

my_used_car.update_odometer(100)
my_used_car.read_odometer()

my_used_car.increment_odometer(1000)
my_used_car.read_odometer()
发布了102 篇原创文章 · 获赞 0 · 访问量 1564
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览