2017-12-25 9 views
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)しか必要としません。しかし、私が​​を呼び出すと、numbersはユーザが入力する値であり、タイトルに見られるように次のエラーが返されます。私はここに何かを逃していますかchannel()1つの必須の位置引数がありません

+0

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

は上記のコードを実行しますに入る。これはPythonコードで重要なことです! –

+0

真剣に、インデントを修正するか、あなたの質問は良いことではありません! –

答えて

0

あなたは、インスタンスTVchannel()メソッドを呼び出す必要があります:**すべてのものがすべき**私たちが見ることができるようにインデントを修正してください

What do u want to watch? 3 
You are currently tuning into Movie 
Press enter to exit 
>>> 
関連する問題