1
Hello I have a typeErro problem. but I don’t know what can be, I’m beginner in python
import random
def ataque(bonus, defesa, dano, bonus_dano):
dano_total = [(random.randint(1, dano)+bonus_dano) for i in range(1)]
ataque_total = [(random.randint(1, 20)) for i in range(1)]
dano_critico = [(random.randint(1, dano)+2*bonus_dano) for i in range(2)]
total_dano_critico=sum(dano_critico)
if ataque_total == 20 and ataque_total + bonus_dano >= defesa:
print(total_dano_critico)
else:
if ataque_total+bonus_dano >= defesa :
print(dano_total)
else:
print("errou")
And what is exactly the error message? Whereas
bonus_dano
is numerical, inataque_total + bonus_dano
you would be adding a list with a number; what would be the expected result of this? By the way, whydano_total
,ataque_total
anddano_critico
are lists?– Woss
of the error in if attack_total+bonus_damage >= defense :, so I put them as lists pq in the sum command it does not sum if it is not list, then I had to write much more code and it was also to have cleaner code.
– bruno boff
I’ll take the list of those that you don’t need. run some tests, see if the problem continues. I can add a number to all the components of a list ?
– bruno boff
thanks for your attention.
– bruno boff