healthPerc = 100 #как этой переменной принимать разные значения,в зависимости от условий выполненых раннее... count = 0 while (count < 1): cell_health = random.randint(0, 100) newHealth = count + cell_health count = count + 1 print('You lost - {0} health.\nYou health: {1}'.format(newHealth, (healthPerc - newHealth))) if (healthPerc - newHealth) > 50: print('Do you want continue?') if (healthPerc - newHealth) < 50: print('You loose!!!')` 

The healthPerc variable can be assigned one of 2 values. Tell me, how can I use one of them depending on the choice? Thank.

    1 answer 1

    What choice are you talking about? It does not specify the conditions depending on which the value of the healthPerc will change. As an example, you can use the following:

     healthPerc = 50 if is_half_health else 100 

    Or this option:

     if full_health: healthPerc = 100 elif is_half_health: healthPerc = 50 elif damage > 50: healthPerc = 25 else: healthPerc = 0 

    Describe in more detail the part of the variable healthPerc can be assigned to one of 2 values, then you can tell what exactly you need (more precisely, how it should be).

    • Thank you for responding. In more detail: The conditions that change the values ​​of healthPerc are entering the number 1 or 2 in the dialog box, such as choosing the "game character", one (figure 1) has a healthPerc equal to 100 at the other (figure 2) 150. The code above should simulate a fight, that is take a certain number of lives from the selected character. Before the battle, either character-1 is chosen for which the healthPerc-100 or character-2 for which is healthPerc-150. How to take life away is understandable, but as in the code above, it’s not clear to substitute different values ​​for the healthPerc (depending on the choice of character 100 or 150) - Oposum
    • If you help me figure it out, I will be very grateful. Perhaps you need to do everything differently. - Oposum
    • @Oposum, I don’t know how you get the answer from the dialog box, so I’ll show using simple input: used_person = int (input ("first or second (1 or 2)? \ N")) healthPerc = 150 if (used_person == 2) else 100 I do not process errors, because Now we are not considering them. Wrong choice is not processed for the same reason. - BOPOH
    • one
      Crow thank you very much, now it works! The answer is not from the dialog box, I was wrong, but through input: Thanks for the support once again. - Oposum