前提・実現したいこと
使用バージョン:Python 3.8.1, sqlite3 3.30.1
ゲームのダメージ計算機をパイソンの中で作成したく思い、作ろうとしています。
この中で実際にダメージを計算する部分を作っています。
発生している問題・エラーメッセージ
変数を使って計算式を使った際に型の違うものを計算している旨のエラーが出ます。
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\gojin\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "C:\Users\gojin\Desktop\sqlite3\damagecalculation.py", line 84, in click dmg = int(int(22 * power * Atktype / Deftype) / 50 +2) * range_rev * mAtk TypeError: unsupported operand type(s) for *: 'int' and 'sqlite3.Cursor'
該当のソースコード
初心者のためかなり長いコードであり、どこを変えるのがいいのかがわからなかったのですべて載せることをお許しください。
Python
1import tkinter as tk 2import sqlite3 as sql 3 4dbpath = 'dex.sqlite3' 5conn = sql.connect(dbpath) 6cur = conn.cursor() 7 8win = tk.Tk() 9win.title('ダメージ計算') 10win.geometry('500x350') 11 12l1 = tk.Label(text = '攻撃側ポケモン名') 13l1.pack() 14a = tk.Entry() 15a.pack() 16a.insert(index = 'insert', string = '') 17 18l2 = tk.Label(text = 'わざ名') 19l2.pack() 20b = tk.Entry() 21b.pack() 22b.insert(index = 'insert', string = '') 23 24l3 = tk.Label(text = '防御側ポケモン名') 25l3.pack() 26c = tk.Entry() 27c.pack() 28c.insert(index = 'insert', string = '') 29 30def click(): 31 32 A = a.get() 33 B = b.get() 34 C = c.get() 35 36 Atk = cur.execute("SELECT A FROM dex WHERE Name = '%s'" % A) 37 SpA = cur.execute("SELECT C FROM dex WHERE Name = '%s'" % A) 38 type1 = cur.execute("SELECT type1 FROM dex WHERE Name = '%s'" % A) 39 type2 = cur.execute("SELECT type2 FROM dex WHERE Name = '%s'" % A) 40 mtype = cur.execute("SELECT type FROM moves WHERE name = '%s'" % B) 41 Def = cur.execute("SELECT B FROM dex WHERE Name = '%s'" % C) 42 SpD = cur.execute("SELECT D FROM dex WHERE Name = '%s'" % C) 43 power = cur.execute("SELECT power FROM moves WHERE name = '%s'" % B) 44 mAtktype = cur.execute("SELECT mtype FROM moves WHERE name = '%s'" % B) 45 46 if type1 == mtype: 47 48 mAtk = 1.5 49 50 if type2 == mtype: 51 52 mAtk = 1.5 53 54 else: 55 56 mAtk = 1.0 57 58 if mAtktype == A: 59 60 Atktype = int(Atk) 61 62 if mAtktype == C: 63 64 Atktype = int(SpA) 65 66 if mAtktype == A: 67 68 Deftype = int(Def) 69 70 if mAtktype == C: 71 72 Deftype = int(SpD) 73 74 bin = tk.BooleanVar() 75 76 if bin.get(): 77 78 range_rev = 0.75 79 80 else: 81 82 range_rev = 1 83 84 dmg = int(int(22 * power * Atktype / Deftype) / 50 +2) * range_rev * mAtk 85 86 print(dmg) 87 88check = tk.Checkbutton(win, variable = bin, text = '範囲補正') 89check.pack() 90 91onButton = tk.Button(win, text = 'Calculate', command = click) 92onButton.pack() 93 94win.mainloop()
試したこと
Power = int(power)のように無理やりint型に変えようとしましたが、cursor型はint型に変換できないとのエラーが出ました。
補足情報(FW/ツールのバージョンなど)
SELECT文にて読みだしている情報はintegerとしてデータベースに格納されていますので、そこにミスはないのではないかと思っております。
回答1件
あなたの回答
tips
プレビュー