class Bicycle:
def __init__(self, color, brand):
self.color = color
self.brand = brand
self.current_speed = 0
def pedal(self, speed_increase):
self.current_speed += speed_increase
def brake(self, speed_decrease):
if self.current_speed >= speed_decrease:
self.current_speed -= speed_decrease
else:
self.current_speed = 0
def show_info(self):
print(f"Color: {self.color}")
print(f"Brand: {self.brand}")
print(f"Current Speed: {self.current_speed} km/h")
# 创建自行车实例
my_bicycle = Bicycle("Red", "Giant")
# 加速
my_bicycle.pedal(10)
my_bicycle.show_info() # 输出:Color: Red, Brand: Giant, Current Speed: 10 km/h
# 再加速
my_bicycle.pedal(15)
my_bicycle.show_info() # 输出:Color: Red, Brand: Giant, Current Speed: 25 km/h
# 刹车
my_bicycle.brake(5)
my_bicycle.show_info() # 输出:Color: Red, Brand: Giant, Current Speed: 20 km/h
# 全力刹车
my_bicycle.brake(20)
my_bicycle.show_info() # 输出:Color: Red, Brand: Giant, Current Speed: 0 km/h