Jay*_*lis 0 python tkinter python-3.x
我正在制作一个口袋妖怪战斗模拟器(在某种程度上就像口袋妖怪摊牌),并且在创建战斗步骤(计算伤害的地方)期间TypeError: can't multiply sequence by non-int of type 'float'发生了错误。
这是我的代码:
from tkinter import *
from tkinter import ttk
def fight():
moveused1 = moveset1.get()
moveused2 = moveset2.get()
if moveused1 == "Tackle":
movetype1 = "Normal"
moverange1 = "Physical"
power1 = "40"
if moveused2 == "Tackle":
movetype2 = "Normal"
moverange2 = "Physical"
power2 = "40"
if moverange1 == "Physical":
Pokemon1Damage = ((2 * 100 / 5 + 2) * power1 * Attack1 / Defence1 / 50 + 2)
if moverange1 == "Special":
Pokemon1Damage = ((2 * 100 / 5 + 2) * power2 * SpAttack2 / SpDefence2 / 50 + 2)
def start():
global moveset1
global moveset2
global HP1
global Attack1
global SpAttack1
global Defence1
global SpDefence1
global HP2
global Attack2
global SpAttack2
global Defence2
global SpDefence2
setup.withdraw()
battle = Tk()
battle.title(pokemon1 + " VS " + pokemon2)
battle.geometry("600x400")
battle.iconbitmap("icon.ico")
if pokemon1 == "Bulbasaur":
HP1 = "231"
Attack1 = "134"
SpAttack1 = "166"
Defence1 = "134"
SpDefence1 = "166"
if pokemon2 == "Bulbasaur":
HP2 = "231"
Attack2 = "134"
SpAttack2 = "166"
Defence2 = "134"
SpDefence2 = "166"
move1 = move1select.get()
move2 = move2select.get()
move3 = move3select.get()
move4 = move4select.get()
Label(battle, text="Battle").pack()
Label(battle, text="").pack()
Label(battle, text=pokemon1 + "'s Move").pack()
moveset1 = ttk.Combobox(battle, state="readonly", values=(move1, move2, move3, move4))
moveset1.current(0)
moveset1.pack()
move5 = move5select.get()
move6 = move6select.get()
move7 = move7select.get()
move8 = move8select.get()
Label(battle, text="").pack()
Label(battle, text=pokemon2 + "'s Move").pack()
moveset2 = ttk.Combobox(battle, state="readonly", values=(move5, move6, move7, move8))
moveset2.current(0)
moveset2.pack()
Button(battle, text="Fight", command=fight).pack()
Run Code Online (Sandbox Code Playgroud)
编辑:这是完整的错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\colli\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\colli\Desktop\Pokemon Battle Buddy\Pokemon Battle Buddy.py", line 19, in fight
Pokemon1Damage = ((2 * 100 / 5 + 2) * power1 * Attack1 / Defence1 / 50 + 2)
TypeError: can't multiply sequence by non-int of type 'float'
Run Code Online (Sandbox Code Playgroud)
您正在乘以字符串和浮点数。这里:
if moverange1 == "Physical":
Pokemon1Damage = ((2 * 100 / 5 + 2) * power1 * Attack1 / Defence1 / 50 + 2)
if moverange1 == "Special":
Pokemon1Damage = ((2 * 100 / 5 + 2) * power2 * SpAttack2 / SpDefence2 / 50 + 2)
Run Code Online (Sandbox Code Playgroud)
power1, power2, Attack1, Defence1, SpAttack2,SpDefence2都是字符串。您应该用在代码中定义它们的整数替换它们。
| 归档时间: |
|
| 查看次数: |
53 次 |
| 最近记录: |