简体   繁体   English

如何修复“类型错误:不能将序列乘以非整数类型的‘浮点数’?

[英]How do I fix 'Type Error: can't multiply sequence by non-int of type 'float'?

I'm making a Pokemon Battle Simulator (like pokemon showdown in a way) and, during the creation of the battle step (where damage is calculated), an error TypeError: can't multiply sequence by non-int of type 'float' occurs.我正在制作一个口袋妖怪战斗模拟器(在某种程度上就像口袋妖怪摊牌),并且在创建战斗步骤(计算伤害的地方)期间,错误类型错误TypeError: can't multiply sequence by non-int of type 'float'发生。

Here's my code:这是我的代码:

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()

Edit: Here is the full error:编辑:这是完整的错误:

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'

You are multiplying strings and float.您正在乘以字符串和浮点数。 Here:这里:

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)

power1 , power2 , Attack1 , Defence1 , SpAttack2 , SpDefence2 are all strings. power1power2Attack1Defence1SpAttack2SpDefence2都是字符串。 You should replace them with integers where you define them in your code.您应该用在代码中定义它们的整数替换它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为公式修复“ TypeError:无法将序列乘以'float'类型的非整数”? - How do I fix “TypeError: can't multiply sequence by non-int of type 'float'” for my formulas? 为什么我会收到“不能将序列乘以‘float’类型的非整数”错误? - Why do I get "can't multiply sequence by non-int of type 'float'" error? 为什么我得到错误不能将序列乘以'float'PYTHON类型的非int - Why do I get error can't multiply sequence by non-int of type 'float' PYTHON 为什么会出现错误:“TypeError:无法将序列乘以‘float’类型的非整数”? - Why do I get the error: "TypeError: can't multiply sequence by non-int of type 'float'"? 错误无法将序列乘以'float'类型的非整数 - Error can't multiply sequence by non-int of type 'float' 不能将序列乘以'float'类型的非整数错误? - can't multiply sequence by non-int of type 'float' error? 错误:无法将序列乘以“float”类型的非整数 - Error: can't multiply sequence by non-int of type 'float' 错误是:无法将序列乘以'float'类型的非整数 - The error was:can't multiply sequence by non-int of type 'float' 如何解决python中的“无法将序列乘以'float'类型的非整数”的问题 - How do I solve the issue “can't multiply sequence by non-int of type 'float'” in python 如何修复 TypeError:不能将序列乘以“numpy.float64”类型的非整数 - How to fix TypeError: can't multiply sequence by non-int of type 'numpy.float64'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM