今天给家里打电话了

         今天给家里打电话,说了半天没用的话。但是心里还是暖暖的,毕竟是自己的亲人。呵呵,大概只能过年的时候才能回家了。

         昨天老婆给我打电话的时候给我策划了好多,心里很感动。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是根据您的要求编写的Python代码实现: ```python class ComDevice: def __init__(self, name, device_type, network): self.name = name self.type = device_type self.network = network def call(self, number): print(f"{self.name} is calling {number}") class MobilePhone(ComDevice): def __init__(self, name, network): super().__init__(name, "Mobile Phone", network) def call(self, number): print(f"{self.name} is calling {number} using mobile network") class Telephone(ComDevice): def __init__(self, name, network, address): super().__init__(name, "Telephone", network) self.address = address def call(self, number): print(f"{self.name} is calling {number} using landline network") class PublicPhone(Telephone): def __init__(self, name, network, address, charge_rate): super().__init__(name, network, address) self.charge_rate = charge_rate def call(self, number, duration): cost = duration * self.charge_rate print(f"{self.name} is calling {number} using public phone, cost is {cost}") def main(): mobile_phone = MobilePhone("Mobile Phone A", "4G") telephone = Telephone("Telephone B", "Landline", "1234 Main Street") public_phone = PublicPhone("Public Phone C", "Landline", "In front of the convenience store", 0.5) xiaohua_number = "123456789" mobile_phone.call(xiaohua_number) telephone.call(xiaohua_number) public_phone.call(xiaohua_number, 5) if __name__ == "__main__": main() ``` 在上面的代码中,我们首先定义了 `ComDevice` 基类,包含了通讯设备的基本属性和方法。然后我们定义了继承自 `ComDevice` 的 `MobilePhone` 手机类,覆盖了父类的 `call()` 方法。接着我们定义了继承自 `ComDevice` 的 `Telephone` 家用固定电话类,增加了地址属性,并且同样覆盖了父类的 `call()` 方法。最后我们定义了继承自 `Telephone` 的 `PublicPhone` 公用电话类,增加了收费标准和收费方法。 在 `main()` 函数中,我们创建了一个手机、一个家用固定电话和一个公用电话,并分别使用它们给一个名叫李大花的人打电话。在使用公用电话打电话的时候,我们还计算了通话的花费,并输出到屏幕上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值