質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

3回答

571閲覧

渡すべき引数が分からない

Ataro

総合スコア0

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/02/14 01:30

ゲームのステータスを計算するアプリケーションを作成しています。
しかし、#属性攻撃力計算関数のところで引数絡みのエラーが発生してしまいます。
以下はエラー文です。

TypeError

1TypeError: Contact_point() missing 12 required positional arguments: 'contact', 'deffence', 'fire_1', 'water_1', 'earth_1', 'light_1', 'dark_1', 'fire_2', 'water_2', 'earth_2', 'light_2', and 'dark_2'

そして、プログラムは以下の通りです。

python3.10

1import tkinter as tk 2 3#物理攻撃力計算関数 4def Attack_point(attack,block): 5 return (attack * attack) / (attack + block) + 0.5 6 7#属性攻撃力計算関数 8def Contact_point(contact,deffence,fire_1,water_1,earth_1,light_1,dark_1,fire_2,water_2,earth_2,light_2,dark_2): 9 fire = fire_1 + (earth_2 - water_2) * 0.5 10 water = water_1 + (fire_2 - earth_2) * 0.5 11 earth = earth_1 + (water_2 - fire_2) * 0.5 12 all_contact = fire_1 + water_1 + earth_1 + light_1 + dark_1 13 if ((fire_1 > water_1) & (fire_1 > earth_1) & (fire_1 > light_1) & (fire_1 > dark_1)): 14 result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((fire_1 / all_contact) / 100 + 0.5) 15 if ((water_1 > fire_1) & (water_1 > earth_1) & (water_1 > light_1) & (water_1 > dark_1)): 16 result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((water_1 / all_contact) / 100 + 0.5) 17 if ((earth_1 > water_1) & (earth_1 > fire_1) & (earth_1 > light_1) & (earth_1 > dark_1)): 18 result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((earth_1 / all_contact) / 100 + 0.5) 19 if ((light_1 > water_1) & (light_1 > earth_1) & (light_1 > fire_1) & (light_1 > dark_1)): 20 result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((light_1 / all_contact) / 100 + 0.5) 21 if ((dark_1 > water_1) & (dark_1 > earth_1) & (dark_1 > light_1) & (dark_1 > fire_1)): 22 result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((dark_1 / all_contact) / 100 + 0.5) 23 Contact_point() 24 25#トップレベルウインドウの表示 26root = tk.Tk() 27root.title("ひまスラ攻撃力チェック") 28root.geometry("350x500") 29 30#Labelウィジェットの生成 31label_1 = tk.Label(root,text="物理攻撃力") 32label_2 = tk.Label(root,text="属性攻撃力") 33label_3 = tk.Label(root,text="敵物理防御力") 34label_4 = tk.Label(root,text="敵属性防御力") 35label_5 = tk.Label(root,text="火属性攻撃力") 36label_6 = tk.Label(root,text="水属性攻撃力") 37label_7 = tk.Label(root,text="木属性攻撃力") 38label_8 = tk.Label(root,text="光属性攻撃力") 39label_9 = tk.Label(root,text="闇属性攻撃力") 40label_10 = tk.Label(root,text="火属性防御力") 41label_11 = tk.Label(root,text="水属性防御力") 42label_12 = tk.Label(root,text="木属性防御力") 43label_13 = tk.Label(root,text="光属性防御力") 44label_14 = tk.Label(root,text="闇属性防御力") 45 46label_15 = tk.Label(root,text="ステータスを入力してください。") 47 48#Entryウィジェットの生成 49attack = tk.Entry(width = 10) 50block = tk.Entry(width = 10) 51contact = tk.Entry(width = 10) 52deffence = tk.Entry(width = 10) 53fire_1 = tk.Entry(width = 10) 54water_1 = tk.Entry(width = 10) 55earth_1 = tk.Entry(width = 10) 56light_1 = tk.Entry(width = 10) 57dark_1 = tk.Entry(width = 10) 58fire_2 = tk.Entry(width = 10) 59water_2 = tk.Entry(width = 10) 60earth_2 = tk.Entry(width = 10) 61light_2 = tk.Entry(width = 10) 62dark_2 = tk.Entry(width = 10) 63 64#Buttonのハンドラ関数 65def judgement(): 66 a = int(attack.get()) 67 b = int(block.get()) 68 c = int(contact.get()) 69 d = int(deffence.get()) 70 f1 = int(fire_1.get()) 71 w1 = int(water_1.get()) 72 e1 = int(earth_1.get()) 73 l1 = int(light_1.get()) 74 d1 = int(dark_1.get()) 75 f2 = int(fire_2.get()) 76 w2 = int(water_2.get()) 77 e2 = int(earth_2.get()) 78 l2 = int(light_2.get()) 79 d2 = int(dark_2.get()) 80 81 s = Attack_point(a,b) + Contact_point(c,d,f1,w1,e1,l1,d1,f2,w2,e2,l2,d2) 82 label_15["text"] = "総合攻撃力:" + str(s) 83 84#Buttonウィジェットの生成 85button = tk.Button(root,text="計算実行",command = judgement) 86 87#各列の割合を指定 88root.columnconfigure(0,weight = 1) 89root.columnconfigure(1,weight = 1) 90root.columnconfigure(2,weight = 1) 91root.columnconfigure(3,weight = 1) 92 93#各行の割合を指定 94root.rowconfigure(0,weight = 1) 95root.rowconfigure(1,weight = 1) 96root.rowconfigure(2,weight = 1) 97root.rowconfigure(3,weight = 1) 98root.rowconfigure(4,weight = 1) 99root.rowconfigure(5,weight = 1) 100root.rowconfigure(6,weight = 1) 101root.rowconfigure(7,weight = 1) 102root.rowconfigure(8,weight = 1) 103root.rowconfigure(9,weight = 1) 104 105#1行目 106label_1.grid(column = 0,row = 0) 107attack.grid(column = 1,row = 0) 108label_3.grid(column = 2,row = 0) 109block.grid(column = 3,row = 0) 110 111#2行目 112label_2.grid(column = 0,row = 1) 113contact.grid(column = 1,row = 1) 114label_4.grid(column = 2,row = 1) 115deffence.grid(column = 3,row = 1) 116 117#3行目 118label_5.grid(column = 0,row = 2) 119fire_1.grid(column = 1,row = 2) 120label_10.grid(column = 2,row = 2) 121fire_2.grid(column = 3,row = 2) 122 123#4行目 124label_6.grid(column = 0,row = 3) 125water_1.grid(column = 1,row = 3) 126label_11.grid(column = 2,row = 3) 127water_2.grid(column = 3,row = 3) 128 129#5行目 130label_7.grid(column = 0,row = 4) 131earth_1.grid(column = 1,row = 4) 132label_12.grid(column = 2,row = 4) 133earth_2.grid(column = 3,row = 4) 134 135#6行目 136label_8.grid(column = 0,row = 5) 137light_1.grid(column = 1,row = 5) 138label_13.grid(column = 2,row = 5) 139light_2.grid(column = 3,row = 5) 140 141#7行目 142label_9.grid(column = 0,row = 6) 143dark_1.grid(column = 1,row = 6) 144label_14.grid(column = 2,row = 6) 145dark_2.grid(column = 3,row = 6) 146 147#8行目 148button.grid(column = 0,row = 7,columnspan = 3) 149 150#9行目 151label_15.grid(column = 0,row = 8,columnspan = 3) 152 153#トップレベルウインドウの表示 154root.mainloop()

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

melian

2022/02/14 01:47 編集

Contact_point 関数の最後で Contact_point() を実行していますが、これは return result とするのではないでしょうか。
guest

回答3

0

(※ 本来は修正依頼の欄に書くべきですが、暴言と取る人が多いためここに書きます)

まず、エラーメッセージを読みましょう。エラーメッセージは暴言でも無いし、ランダムに表示される「大凶」とかのようなものでもありません。インタプリタ等からのメッセージです。

TypeError: Contact_point() missing 12 required positional arguments: 'contact', 'deffence', 'fire_1', 'water_1', 'earth_1', 'light_1', 'dark_1', 'fire_2', 'water_2', 'earth_2', 'light_2', and 'dark_2' [訳] TypeError: Contact_point関数で、足りない引数が12個あります。"contact", "deffence", "fire_1", ... とか。 [言い換えた訳] なあ、Contact_pint関数の引数足りないんじゃね? "contact", "deffence", "fire_1"とかみたいな引数はどこ行ったん?

つまり、引数が足りない事が原因。

で、問題の部分を見ると、なんか

def Contact_point(contact,deffence,fire_1,water_1,earth_1,light_1,dark_1,fire_2,water_2,earth_2,light_2,dark_2): fire = fire_1 + (earth_2 - water_2) * 0.5 water = water_1 + (fire_2 - earth_2) * 0.5 earth = earth_1 + (water_2 - fire_2) * 0.5 all_contact = fire_1 + water_1 + earth_1 + light_1 + dark_1 if ((fire_1 > water_1) & (fire_1 > earth_1) & (fire_1 > light_1) & (fire_1 > dark_1)): result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((fire_1 / all_contact) / 100 + 0.5) if ((water_1 > fire_1) & (water_1 > earth_1) & (water_1 > light_1) & (water_1 > dark_1)): result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((water_1 / all_contact) / 100 + 0.5) if ((earth_1 > water_1) & (earth_1 > fire_1) & (earth_1 > light_1) & (earth_1 > dark_1)): result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((earth_1 / all_contact) / 100 + 0.5) if ((light_1 > water_1) & (light_1 > earth_1) & (light_1 > fire_1) & (light_1 > dark_1)): result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((light_1 / all_contact) / 100 + 0.5) if ((dark_1 > water_1) & (dark_1 > earth_1) & (dark_1 > light_1) & (dark_1 > fire_1)): result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((dark_1 / all_contact) / 100 + 0.5) Contact_point() # <- これ

これっぽいですね。仮に引数を適切に渡したとしても、再帰的呼び出しになり、無限ループ的な状態に陥るはずです。(だって終了の条件が無いんだし)

恐らく、return result では?

他の方とのやり取りで、

サイトを見てこれかなって思ったものを代入したのですが、間違っておりました。

もともとはreturn resultとしていたのですが、そちらでもエラーが発生したためです。

とありますが、これも一緒です。
エラーメッセージを読みましょう。エラーメッセージにヒントが隠されています。つか、Python.exeとかからの返信のようなものです。それすら読まないのでしたらプログラミングやめた方がいいです。
だって、相手の話を聞こうとすらせずに早合点とかして暴走するようなものですから。そんな人ってコミュニケーション取れますかね?

まずはメッセージを読みましょう

投稿2022/02/14 06:26

BeatStar

総合スコア4958

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

エラーメッセージに行番号が表示されていいると思いますが、その行はどこですか?

python

1 Contact_point()

と引数のない関数呼出しがありますけど、そこではないですか?
自分自身を呼び出すと無限ループになってしまうので、 return result とかにしたかったのかなと想像します。

投稿2022/02/14 01:43

編集2022/02/14 02:47
shiracamus

総合スコア5406

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

python

1def Contact_point(contact,deffence,fire_1,water_1,earth_1,light_1,dark_1,fire_2,water_2,earth_2,light_2,dark_2): 2 fire = fire_1 + (earth_2 - water_2) * 0.5 3# 中略 4 if ((dark_1 > water_1) & (dark_1 > earth_1) & (dark_1 > light_1) & (dark_1 > fire_1)): 5 result = ((contact * contact) / (contact + deffence) + 0.5) * (fire + water + earth + light_1 + dark_1) * ((dark_1 / all_contact) / 100 + 0.5) 6 Contact_point() # <----- これ何? 7 8

投稿2022/02/14 01:41

ozwk

総合スコア13521

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Ataro

2022/02/14 02:41

サイトを見てこれかなって思ったものを代入したのですが、間違っておりました。 もともとは**return result**としていたのですが、そちらでもエラーが発生したためです。
ozwk

2022/02/14 04:28

そのときなんというエラーが出たんですか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問