-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcar
More file actions
35 lines (28 loc) · 1.04 KB
/
car
File metadata and controls
35 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
"""一个可用于表示汽车的类"""
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