How can I loop this to create the skeleton of an auto-battler/Idle game

Would a for loop be required for what I want? I’m ignorant, but in school for comp sci. You can look at the code there.
Feb 02 5:16 AM - Codeshare

Well, we don’t know what you want, so it’s hard to say what would be required for it. It also isn’t clear where you imagine using the loop, what it would loop over, or how you intend for it to contribute to the project.

Please read the pinned thread to understand how to post code in the forum with proper formatting. We shouldn’t have to go to a third-party site for this. Then try to explain what issue you are running into with the existing code: does it give a wrong result? Is it missing functionality? Something else?

Thanks, and sorry for my ignorance and inaccuracy. I figured out how to loop it, and gained a better understanding of while and if. I am now trying to figure out how to add these two variables consecutively. I am trying to get Etotal as the consecutive sum of Exp value and Et (which is just the next Exp value after the refresh, and they’re both random values between 5,12 multiplied by .100). So I want a variable that stores the added values of all the Exp earned, but can’t seem to get it. I feel like I’m missing something simple.

while HPm <= 0 :
              Exp = e * .100
              q = random.choice(WhipQ)
              print("The "+str(a)+" Was "+str(q)) 
              print("You gained "+str(Exp)+" Exp!")
              a = None
              a = random.choice(Mon)
              e = None
              e = random.randint(5,12)
              Et = e * .100
              Etotal = Et + Exp
              HPm = HPm + random.randint(20,30)
              Killz = Killz + 1
              if Killz == 4 :

4 rather than 14 spaces for indents is generally preferred ;-). Anyway, Etotal initialization before the loop and change Etotal = to Etotal +=.

Etotal = 0
while HPm <= 0:
    Etotal += Et + Exp
1 Like

Wow, I didn’t know adding the operator on that side would do that, I knew I was missing something simple. Thanks for the advice

augmented assignment

Just FYI, you could also have written

Etotal += Et + Exp

using regular addition and assignment:

Etotal = Etotal + Et + Exp

This equivalence isn’t guaranteed to be the case for all types (since a class could theoreticlaly define __iadd__, etc to do anything it wanted), but for numbers like in this case, it is indeed the case.