zoukankan      html  css  js  c++  java
  • python 类的简单运用

    定义一个手机类, 具有打电话和录音的功能,打电话的时候可以录音,也可以不录音。

    class MobilePhone():
        def __init__(self,brand,type,color,phone_num):
            self.brand=brand #品牌
            self.type=type #类型
            self.color=color #颜色
            self.phone_num=phone_num #手机号
    
        def call(self):
            print('{}正在拨打电话...'.format(self.phone_num))
            try:
                choice=int(input('请问您是否需要录音?
    输入1(录音),输入2(不录音):'))
                if choice==1:
                    self.record()
                elif choice==2:
                    print('您未进入录音模式,请放心使用!')
                else:
                    while True:
                        print('33[31;1m您的输入有误!33[0m')
                        choice = int(input('请输入以下选项执行操作:
    输入1(录音),输入2(不录音),输入3(结束通话):'))
                        if choice == 1:
                            self.record()
                            break
                        elif choice == 2:
                            print('您未进入录音模式,请放心使用!')
                            break
                        elif choice == 3:
                            print('感谢您的使用,再见!')
                            break
            except Exception as e:
                print("33[31;1m您的输入有误,本次通话结束!33[0m")
    
        def record(self):
            print('您的手机{},颜色为{},当前已进入通话录音...'.format(self.type,self.color))
    
    
    # 初始化对象/实例化对象
    phone=MobilePhone('iphone','iphone 11','奢侈灰','13458215862')
    phone.call()

  • 相关阅读:
    80211-pcap包类型有3种link type
    node搭建多人博客
    mac快捷键
    阿里云搭建svn
    linux 常用命令
    node 日志
    启动tomcat
    kill redis
    利用新浪接口获取客户端ip
    网站loading的几种实现方法
  • 原文地址:https://www.cnblogs.com/ITester520/p/12068990.html
Copyright © 2011-2022 走看看