実現したいこと
Pyhtonでクラスの勉強がてらにポケモンを作っているのですが、子クラスにて親クラスのプロパティの定義のやり方がわかりません。
「pokemon_category」を子クラスにて"イーブイ"と定義したいのですが、superの使い方が違うようで引数が足りないとエラーになります。
どのように修正すれば親クラスのプロパティを子クラスにて定義し、インスタンスできるのかをご教授いただければと思います。
また厚かましいお願いになりますが、参考サイトなどあれば合わせて教えていただけると助かります。
該当のソースコード
Python
1class pokemon: 2 3 #初期化 4 def __init__(self,name, pokemon_category, category, attribute, height, weight, propertys, hp, attack, defense, special_attack, special_defense, rapidity, skil1, skil2, skil3, skil4): 5 6 #名前 7 self.name = name 8 9 #ポケモンの種類 10 self.pokemon_category = pokemon_category 11 12 #分類 13 self.category = category 14 15 #属性 16 self.attribute = attribute 17 18 #高さ 19 self.height = height 20 21 #重さ 22 self.weight = weight 23 24 #特性 25 self.propertys = propertys 26 27 #HP 28 self.hp = hp 29 30 #こうげき 31 self.attack = attack 32 33 #ぼうぎょう 34 self.defense = defense 35 36 #とくこう 37 self.special_attack = special_attack 38 39 #とくぼう 40 self.special_defense = special_defense 41 42 #すばやさ 43 self.rapidity = rapidity 44 45 #技1 46 self.skil1 = skil1 47 48 #技2 49 self.skil2 = skil2 50 51 #技3 52 self.skil3 = skil3 53 54 #技4 55 self.skil4 = skil4 56 57 #わざ1 58 def attack1(self): 59 print("{0}の{1}!",format(self.name,self.skil1)) 60 61 #わざ2 62 def attack2(self): 63 print("{0}の{1}!",format(self.name,self.skil2)) 64 65 #わざ3 66 def attack3(self): 67 print("{0}の{1}!",format(self.name,self.skil3)) 68 69 #わざ4 70 def attack4(self): 71 print("{0}の{1}!",format(self.name,self.skil4)) 72 73 74#子クラス 75class eevee(pokemon): 76 def __init__(self, name, category, attribute, height, weight, propertys, hp, attack, defense, special_attack, special_defense, rapidity, skil1, skil2, skil3, skil4): 77 super().__init__(name, pokemon_category, category, attribute, height, weight, propertys, hp, attack, defense, special_attack, special_defense, rapidity, skil1, skil2, skil3, skil4) 78 self.pokemon_category = "イーブイ" 79 80 81 82 83eve = eevee("ブイ太郎","進化ポケモン","ノーマル","0.3m","6.5kg","にげあし",4,4,3,3,4,4,"たいあたり","でんこうせっか","あなをほる","にどげり") 84print(eve.pokemon_category) 85
回答1件
あなたの回答
tips
プレビュー