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

容|
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是用户输入的值,如标题所示,它将返回以下错误。我在这里想念什么吗?

斯里赛拉

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

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

运行上面的代码:

What do u want to watch? 3
You are currently tuning into Movie
Press enter to exit 
>>> 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ArrayField缺少1个必需的位置参数

__init __()缺少1个必需的位置参数

缺少1个必需的位置参数:“ pk”

缺少1个必需的位置参数:“键”

python缺少1个必需的位置参数

AssertTrue 缺少 1 个必需的位置参数

缺少1个必需的位置参数:“循环”

缺少 1 个必需的位置参数:“数字”

缺少1个必需的位置参数:'self'

缺少1个必需的位置参数:“ msg”

缺少1个必需的位置参数

缺少 1 个必需的位置参数 dt

函数缺少 1 个必需的位置参数

缺少 1 个必需的位置参数 [Telebot]

method1()缺少1个必需的位置参数:“ self”

__init__() 缺少 1 个必需的位置参数:'self'

类型错误:post() 缺少 1 个必需的位置参数

类型错误:readData() 缺少 1 个必需的位置参数:“数据”

TypeError:detail()缺少1个必需的位置参数:“ request”

TypeError:predict()缺少1个必需的位置参数:“ params”

多处理,缺少 1 个必需的位置参数:“响应”

setUpClass()缺少1个必需的位置参数:“ cls”

TypeError:fit()缺少1个必需的位置参数:'y'

load_model()缺少1个必需的位置参数:“ filepath”

TypeError:append()缺少1个必需的位置参数:“ values”

django 模板标签缺少 1 个必需的位置参数:值

geopy TypeError:geocode()缺少1个必需的位置参数:“ query”

TypeError:setDocumentLocator()缺少1个必需的位置参数:“ locator”

Django模型属性:缺少1个必需的位置参数: