Pythonでptnaという人口無能のコードを書いています。
しかし、protype.pyを実行するとエラーが出てしまいます。
解決策を教えてほしいです。
prototype.py
1from ptna import * 2"""実行ブロック 3""" 4 5def prompt(obj): 6 """ピティナのプロンプトを作る関数 7 戻り値 "Ptnaオブジェクト名:応答オブジェクト名 > " 8 """ 9 return obj.get_name() + ":" + obj.get_responder_name() + "> " 10 11print("Ptna System prototype : ptna") 12ptna = Ptna("ptna") 13 14while True: 15 inputs=input(" > ") 16 if not inputs: 17 print("ばいばい") 18 break 19 response=ptna.dialogue(inputs) 20 print(prompt(ptna), response)
error
1ptna = Ptna("ptna") 2TypeError: Ptna() takes no arguments
すみません、ptna.pyとresponder.pyのコードも添付しておきます。
ptna.py
1from responder import * 2 3class Ptna: 4 """ピティナの本体クラス 5 """ 6 def _init_(self, name): 7 """Ptnaオブジェクトの名前をnameに格納 8 RandomREsponderオブジェクトを生成してresponderに格納 9 10 @param name Ptnaオブジェクトの名前 11 """ 12 self.name = name 13 self.responder = RandomResponder("Random") 14 15 def dialogue(self, input): 16 """応答オブジェクトのresponse()を呼び出して 17 応答文字列を取得する 18 19 @param input ユーザーによって入力された文字列 20 戻り値 応答文字列 21 """ 22 return self.responder.response(input) 23 24 def get_responder_name(self): 25 """応答オブジェクトの名前を返す 26 """ 27 return self.responder.name 28 29 def get_name(self): 30 """Ptnaオブジェクトの名前を返す 31 """ 32 return self.name
responder.py
1import random 2 3class Responder: 4 """応答クラスのスーパークラス 5 """ 6 def _init_(self, name): 7 """Responderオブザーバーの名前をnameに格納 8 9 @param name Responderオブジェクトの名前 10 """ 11 self.name = name 12 13 def response(self, input): 14 """オーバーライドを前提としたresponse()メソッド 15 16 @param input 入力された文字列 17 戻り値 空の文字列 18 """ 19 return "" 20 21 def get_name(self): 22 """応答オブジェクトの名前を返す 23 """ 24 return self.name 25 26class RepeatResponder(Responder): 27 """オウム返しのための行うサブクラス 28 """ 29 def response(self,input): 30 """応答文字列を作って返す 31 32 @param input 入力された文字列 33 """ 34 return "{}ってなに?".format(input) 35 36class RandomResponder(Responder): 37 """ランダムな応答のための行うサブクラス 38 """ 39 def _init_(self, name): 40 """Responderオブジェクトの名前を引数にして 41 スーパークラスの_init_()を呼び出す 42 ランダムに抽出するメッセージを格納したリストを作成 43 44 @param name Responderオブジェクトの名前 45 """ 46 super()._init(name) 47 self.response = ["いい天気だね", "君はパーリーピーポー", "10円拾った"] 48 49 def response(self, input): 50 """応答文字列を作って返す 51 52 @param input 入力された文字列 53 戻り値 リストからランダムに抽出した文字列 54 """ 55 return (random.choice(self.responses))
ptna.pyのソースコードはどうなっていますか?
回答2件
あなたの回答
tips
プレビュー