EvilZone

Programming and Scripting => Scripting Languages => : sarat1998 February 08, 2013, 06:53:05 PM

: Dynamic number of loops
: sarat1998 February 08, 2013, 06:53:05 PM
I was wondering if there is any code to generate a dynamic number of loops (where the number is specified by the user) in python. Any help would be deeply appreciated.
: Re: Dynamic number of loops
: EmilKXZ February 08, 2013, 07:08:08 PM
Sure, just do a loop, like "for (i=0; i=random(from,to); i++):"

The random in that place should find the last execution of the loop, and then execute the loop that quantity of times.

I don't know the actual implementation because I have not learned Python yet, but that's the basic structure of what you want to do... I guess...

Off-topic: Sorry for the bad english, still not fully awaken.
: Re: Dynamic number of loops
: sarat1998 February 08, 2013, 07:38:33 PM
thanks for the reply man!
: Re: Dynamic number of loops
: Mike245 February 09, 2013, 05:48:53 AM
I am guessing you are new to programming then? This is something very easy to accomplish. Do something similar to this.


  x = int(input("Enter number: "))
  for i in range(x):
      #do something here.


At least that is the general idea. Hope it helps.
: Re: Dynamic number of loops
: sarat1998 February 09, 2013, 06:23:58 AM
thanks for the reply but I found the solution. We have to use product in itertools to do this.