Python Forum
Python Turtle and order of implementation query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Turtle and order of implementation query
#1
Hello all, first post here so hopefully this is in the right place.
Would be greatful iff someone could help me understand something, Im just starting to
learn python as a hobbyist and was doing some fractal tutorials with Turtle.

Came across code for a fractal tree, as bellow.
import turtle
PROGNAME = 'Fractal Tree'

myPen = turtle.Turtle()
myPen.up()
myPen.left(90)
myPen.back(300)
myPen.down()
myPen.speed(10)
myPen.color("#000000")

#Recursive draw, where x is length
def draw(x):
    if(x<5):
        return
    else:
        myPen.forward(x)
        myPen.left(30)
        draw(3*x/4)
        myPen.right(60)
        draw(3*x/4)
        myPen.left(30)
        myPen.back(x)

# call draw
draw(300)
Now I thought I understood all this untill noticing when running the programme that turtle always draws the left track untill x hits 5, then traces back and does the next left turn till again x hits 5.

I was expecting the programme to draw one y fork, then another smaller y fork comming from the left of the first and so on till x hits 5.

So i guss my question is why does python draw a single line always executing the left turn untill x hits its < cut off, instead of going through all of the commands within the else loop first?

I hope that makes sense?
Reply


Messages In This Thread
Python Turtle and order of implementation query - by Parsleigh - Mar-02-2019, 10:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python implementation of Longest Common Substring problem Bolt 0 566 Sep-17-2023, 08:31 PM
Last Post: Bolt
  list the files using query in python arjunaram 0 675 Mar-28-2023, 02:39 PM
Last Post: arjunaram
  Turtle.setpos() vs text position on screen query ElectronWrangler 0 1,624 Nov-26-2022, 02:39 AM
Last Post: ElectronWrangler
  python sql query single quote in a string mg24 1 1,082 Nov-18-2022, 08:01 PM
Last Post: deanhystad
  "SUMIF" type query in Python (help required) BlainEillimatta 0 859 Oct-06-2022, 09:08 AM
Last Post: BlainEillimatta
  MSSQL query not working in Python kat35601 0 925 Apr-12-2022, 06:44 PM
Last Post: kat35601
  Error using mariadb select query with form in python? shams 2 2,022 Jul-29-2021, 12:30 PM
Last Post: shams
  Understand order of magnitude performance gap between python and C++ ThelannOryat 4 2,725 Mar-17-2021, 03:39 PM
Last Post: ThelannOryat
  What is the Python Implementation for This? pythonflea 5 2,501 Feb-08-2021, 08:18 PM
Last Post: buran
  Python 3 Turtle - Screen Events and Coords peteralien 0 1,695 Aug-18-2020, 11:25 PM
Last Post: peteralien

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020