# coding:utf-8

CHANNEL = ["1", "2", "3", "4", "5", "6",

"7", "8", "9", "10", "11", "12"]

class Television(object):

"""模拟电视机"""

def __init__(self, channel=1, volume=0):

self.channel = channel

self.volume = volume

@property

def change_volume(self):

"""调音量"""

volume = None

while not volume:

volume = raw_input("请输入音量(0~100):")

try:

volume = int(volume)

except:

print "请输入正确的音量"

volume = None

if (volume > 100) or (volume < 0):

print "输入音量范围有误,请重新输入"

volume = None

elif volume == 0:

print "你现在是静音状态"

else:

print "目前电视的音量是", volume

self.volume = volume

@property

def change_channel(self):

"""调频道"""

channel = None

while not channel:

channel = raw_input("请输入频道(1~12):")

try:

channel = int(channel)

except:

print "请输入正确的频道"

channel = None

self.channel = channel

print "目前电视频道是channel"+ str(channel),

print "它是"+CHANNEL[channel]

def main():

television = Television()

choice = None

while choice != "0":

print

"""模拟电视

0 - 关机

1 - 换台

2 - 调音量

"""

choice = raw_input("""请输入选项:""")

if choice == "0":

print "再见"

elif choice == "1":

television.change_channel

elif choice == "2":

television.change_volume

else:

print "请输入正确的选项"

if __name__ == '__main__':

main()

attributeerror python_python练习类的时候遇到了AttributeError?相关推荐

  1. mro python_Python新式类的方法解析顺序MRO与Super

    新式类与经典类的方法解析顺序 MOR(方法解析顺序) 经典类:深度优先 DFS python3以前 新式类:广度优先 python2.2 新式类:广度优先的C3算法实现(拓扑排序) BFS pytho ...

  2. python类中的属性分为类属性和实例属性两种_python从入门到大神---1、初始化实例、类属性、方法...

    python从入门到大神---1.初始化实例.类属性.方法 一.总结 一句话总结: 方法不加括号是代码段:感觉python方法和js,php很类似,不加括号是代码段,加括号变成方法,比如f,f() 1 ...

  3. “AttributeError: type object ‘RocCurveDisplay‘ has no attribute ‘from_predictions‘ “.

    "AttributeError: type object 'RocCurveDisplay' has no attribute 'from_predictions' ". 目录 & ...

  4. Python元类编程

    文章目录 property动态属性 \__getattr\_\_ \__getattribute__ 属性描述符 属性的查找顺序 自定义元类 metaclass 元类实现简单orm property动 ...

  5. AttributeError: ‘FPDF‘ object has no attribute ‘unifontsubset‘

    AttributeError: 'FPDF' object has no attribute 'unifontsubset' 目录 AttributeError: 'FPDF' object has ...

  6. 成功解决AttributeError: 'GradientBoostingRegressor' object has no attribute 'staged_decision_function'

    成功解决AttributeError: 'GradientBoostingRegressor' object has no attribute 'staged_decision_function' 解 ...

  7. AttributeError系列之:AttributeError: 'tuple' object has no attribute 'shape'

    翻译:属性错误,tuple对象没有shape属性. 这往往发生在我们对一个tuple类型数据,调用成员变量shape所致(a.shape 或 a.shape[]). 所以要查看调用发生处,看看自己的数 ...

  8. 第一次使用scrapy爬豆瓣top250 报错 AttributeError Requset has no attribute dont_filter 和 meta

    首次学习scrapy框架来爬取豆瓣Top250,在写完代码执行时,报了AttributeError: 'Request' object has no attribute 'meta' 还有Attrib ...

  9. Python 中 AttributeError: ‘NoneType‘ object has no attribute ‘X‘ 错误

    文章目录 AttributeError: 'NoneType' object has no attribute 'X' 介绍 AttributeError: 'NoneType' object has ...

最新文章

  1. 程序员拯救乐坛?OpenAI用“逆天”GPT2.0搞了个AI音乐生成器
  2. C#用Tesseract进行OCR识别,可识别中英日韩所有语言
  3. 机器学习常用激活函数
  4. a标签代替input[button]
  5. java.sql.sqlexception: 无效的名称模式:_PSQLException:错误:关系&ldquo; TABLE_NAME&rdquo;不存在...
  6. 【转】C# DateTime 日期计算
  7. hadoop深入研究:(五)——Archives
  8. AE插件Stardust for mac(最强粒子特效)
  9. Intellij IDEA连接Spark集群
  10. android弹窗不能手动关闭_Android弹窗的实现及相关bug
  11. asp.net 后台方法和js方法互动
  12. Centos禁止屏幕虚拟键盘弹出
  13. 眼图观测实验报告_通信原理实验报告 -
  14. echarts 鼠标弹框显示百分比柱状图显示百分比
  15. 计算机驱动空间的c盘不足怎么办,如果C驱动器空间不足,该怎么办
  16. Belief propagation
  17. 阿里P9手写的Java核心开发手册(2022版)覆盖P5到P8所有技术栈
  18. Word的样式库在 选项卡中_word排版应用:如何创建文本样式和表格样式
  19. 期货反向跟单门槛高吗,中小群体个人能不能做
  20. irobot擦地机器人故障_Irobot Braava380t擦地机器人 操作使用说明

热门文章

  1. 海外精致办公名片展示样机|智能贴图 Mockup名片模板
  2. UI设计干货素材|动态交互插画模板
  3. 优质淘宝产品描述页模板框架PSD分层模板,美工实用素材
  4. 优秀PSD电商促销BANNER模板|垂直化内容电商页面设计,需要注意哪些问题?
  5. UI设计干货模板|首页设计技巧
  6. 地震勘探英文专业文章中的经典句子(1)
  7. DPDK笔记 RSS(receive side scaling)网卡分流机制
  8. Flink批处理练习
  9. netty大白话--字符串的收发(三)
  10. 可以分屏的软件_Screen分屏软件下载|Screen+专业分屏 免费版v1.4.25 下载