I have a piece of code in Pycharm , and I want to loop just a part of it, not with the beginning part where are located the login info. Let's say that I want to loop from the 44 line to 99 and only for 20 loops.

closed as off-topic by Niels van Reijmersdal, NarendraC, Ray Oei, alecxe Mar 25 at 14:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – Niels van Reijmersdal, NarendraC, Ray Oei, alecxe
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Hi Alex Alex. It's important for the replies to receive an "accepted" flag is you find them well-completed. If you find some of the answers give you the idea you were looking for, I'd suggest to mark it as accepted. – João Farias Mar 24 at 19:19


start = 1
multiply = start * 2
divided = multiply / 3

Now, let's say you want to multiply by two 20 times:

start = 1
multiply = multiply_value(value = start, number_of_times = 20)
divided = multiply / 3

def multiply_value(value, number_of_times):
   if(number_of_times <= 0):
      return value
      return multiply_value(value * 2, number_of_times - 1)

Alternatively, you could use a for loop:

def multiply_value(value, number_of_times):
       result = 1
       for i range(0, number_of_times):
           result = result * 2
       return result

I suggest reading the section 4 of this Learn X in Y Minutes page.


Loops are well documented: https://wiki.python.org/moin/ForLoop

for x in range(0, 3):
    print "We're on time %d" % (x)

Suggest you do some reading on Python fundamentals:

Not the answer you're looking for? Browse other questions tagged or ask your own question.