Author Topic: Dynamic number of loops  (Read 4248 times)

0 Members and 1 Guest are viewing this topic.

Offline sarat1998

  • /dev/null
  • *
  • Posts: 10
  • Cookies: 1
    • View Profile
Dynamic number of loops
« on: 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.

Offline EmilKXZ

  • Peasant
  • *
  • Posts: 109
  • Cookies: 10
  • likes monies :p
    • View Profile
    • EmilKXZ
Re: Dynamic number of loops
« Reply #1 on: 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.

Offline sarat1998

  • /dev/null
  • *
  • Posts: 10
  • Cookies: 1
    • View Profile
Re: Dynamic number of loops
« Reply #2 on: February 08, 2013, 07:38:33 pm »
thanks for the reply man!

Mike245

  • Guest
Re: Dynamic number of loops
« Reply #3 on: 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.

Offline sarat1998

  • /dev/null
  • *
  • Posts: 10
  • Cookies: 1
    • View Profile
Re: Dynamic number of loops
« Reply #4 on: 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.