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()

  • 相关阅读:
    Linux上安装软件
    VIM的使用
    Linux命令(系统管理)
    django潜心之路4--模型
    django潜行之路3-模板
    django潜行之路2---视图
    django潜行之路1
    sql基础
    Mysql数据库总结
    反爬虫机制
  • 原文地址:https://www.cnblogs.com/ITester520/p/12068990.html
Copyright © 2011-2022 走看看