首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >channel()缺少1个必需的位置参数

channel()缺少1个必需的位置参数
EN

Stack Overflow用户
提问于 2017-12-25 14:36:22
回答 1查看 1.1K关注 0票数 1
代码语言:javascript
复制
class Television(object):

    def __init__(self, lst):
        self.lst = lst

    def channel(self, number):
        print("You are currently tuning into" + self.lst[number-1])


def volume(reduce, loudness=0):
    loudness -= reduce
    return loudness


def main():
    channel = ['News','Sport','Movie','Music','Kids']
    TV = Television(channel)
    numbers = int(input("What do u want to watch?"))
    watch = Television.channel(numbers)
    reduce = int(input("Too loud? Reduce volume!"))
    adjust = Television(reduce)

main()

input("Press enter to exit")

如上面的代码所示,channel方法只需要1个参数,即number。但是,当我调用Television.channel(numbers) (其中numbers是供用户输入的值)时,它返回以下错误,如标题中所示。我是不是漏掉了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-25 15:32:16

您需要在实例TV上调用channel()方法

代码语言:javascript
复制
class Television(object):
    def __init__(self, lst):
        self.lst = lst

    def channel(self, number):
        print("You are currently tuning into " + self.lst[number-1])

def main():
    channels = ['News', 'Sport', 'Movie', 'Music', 'Kids']
    TV = Television(channels)
    number = int(input("What do u want to watch? "))
    watch = TV.channel(number)    

main()

input("Press enter to exit ")

运行上面的代码:

代码语言:javascript
复制
What do u want to watch? 3
You are currently tuning into Movie
Press enter to exit 
>>> 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47966280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档