鱼C论坛

 找回密码
 立即注册
查看: 1729|回复: 4

[已解决]萌新求助,望大佬帮忙

[复制链接]
发表于 2020-8-3 12:25:54 | 显示全部楼层
要继承自 Car 类

  1. from car import Car


  2. class ElectricCar(Car):
  3.     def __init__(self, brand, size):
  4.         super().__init__(brand, size)
  5.         self.battery = 100
  6.         self.rm = 100

  7.     def battery(self):
  8.         print('The electric capacity of electric vehicles is: ' + self.battery)

  9.     def rm(self):
  10.         print('The estimated remaining mileage of electric vehicle is: ' + self.rm)

  11.     def running(self, C):
  12.         C = int(C)
  13.         self.miles += C
  14.         self.rm -= C
  15.         self.battery -= (0.1) * C


  16. my_new_car = ElectricCar('Tesla', 'Model S')
  17. my_new_car.running(55)
  18. my_new_car.rm()
  19. my_new_car.battery()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-4-1 11:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表