title: Function with varying number of For Loops (python)
body: <p>My problem is difficult to explain.</p>
  
  <p>I want to create a function that contains nested for loops,<br>
  the amount of which is proportional to an argument passed to the function.</p>
  
  <p>Here's a hypothetical example:</p>
  
  <pre><code>Function(2)
  </code></pre>
  
  <p>...would involve...</p>
  
  <pre><code>for x in range (y):
      for x in range (y):
          do_whatever()
  </code></pre>
  
  <p>Another example...  </p>
  
  <pre><code>  Function(6)
  </code></pre>
  
  <p>...would involve...</p>
  
  <pre><code>for x in range (y):
      for x in range (y):
          for x in range (y):
              for x in range (y):
                  for x in range (y):
                      for x in range (y):
                          whatever()
  </code></pre>
  
  <p>The variables of the for loop (y) are NOT actually used in the nested code.  </p>
  
  <p>Your first thought might be to create ONE for loop, with a range that is to the power of the number argument...<br>
  THIS CAN NOT WORK because the product would be HUGE. I have instances required where there are 8 nested for loops.<br>
  The product is too large for a range in a for loop.</p>
  
  <p>There are other arguments needed to be passed to the function, but I can handle that myself.</p>
  
  <p>Here's the code
  (it creates the Snowflake Fractal)</p>
  
  <pre><code>from turtle import *
  length = 800
  speed(0)
  
  def Mini(length):
      for x in range (3):
          forward(length)
          right(60)
  
  penup()
  setpos(-500, 0)
  pendown()   
  
  choice = input("Enter Complexity:")
  
  if choice == 1:
      for x in range (3):
          forward(length)
          left(120)
  
  elif choice == 2:
      for x in range (3):
          Mini(length/3)
          left(120)
  
  if choice == 3:
      for x in range (6):
          Mini(length/9)
          right(60)
          Mini(length/9)
          left(120)
  
  if choice == 4:
      for y in range (6):
          for x in range (2):
              Mini(length/27)
              right(60)
              Mini(length/27)
              left(120)
          right(180)
          for x in range (2):
              Mini(length/27)
              right(60)
              Mini(length/27)
              left(120)
  
  if choice == 5:
      for a in range (6):
          for z in range (2):
              for y in range (2):
                  for x in range (2):
                      Mini(length/81)
                      right(60)
                      Mini(length/81)
                      left(120)
                  right(180)
                  for x in range (2):
                      Mini(length/81)
                      right(60)
                      Mini(length/81)
                      left(120)
              right(180)
          right(180)
  
  if choice == 6:
      for c in range (6):
          for b in range (2):
              for a in range (2):
                  for z in range (2):
                      for y in range (2):
                          for x in range (2):
                              Mini(length/243)
                              right(60)
                              Mini(length/243)
                              left(120)
                          right(180)
                          for x in range (2):
                              Mini(length/243)
                              right(60)
                              Mini(length/243)
                              left(120)
                      right(180)
                  right(180)
              right(180)
          right(180)
  
  if choice == 7:
      for a in range (6):
          for b in range(2):
              for c in range (2):
                  for d in range (2):
                      for e in range (2):
                          for f in range (2):
                              for y in range (2):
                                  for x in range (2):
                                      Mini(length/729)
                                      right(60)
                                      Mini(length/729)
                                      left(120)
                                  right(180)
                                  for x in range (2):
                                      Mini(length/729)
                                      right(60)
                                      Mini(length/729)
                                      left(120)
                              right(180)
                          right(180)
                      right(180)
                  right(180)
              right(180)
          right(180)
  </code></pre>
  
  <p>I'd appreciate any help you can give me at all,<br>
  though if you suggest a different method (such as recursion),<br>
  please don't just paste the code; instead, suggests some ideas that could put me in the right direction.</p>
  
  <p>(The algorithm is for a Specialist Math Assignment)</p>
  
  <hr>
  
  <p>specs:<br>
  Python 2.7.1<br>
  Turtle<br>
  IDLE<br>
  Windows7</p>