Problem with the python Random function

Asked

Viewed 59 times

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")
  • 1

    And what is exactly the error message? Whereas bonus_dano is numerical, in ataque_total + bonus_dano you would be adding a list with a number; what would be the expected result of this? By the way, why dano_total, ataque_total and dano_critico are lists?

  • 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.

  • 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 ?

  • thanks for your attention.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.