User-defined function | Function call |
def functionname(parameters): #function body return | functionname(parameters) |
def snowflake(): size = 10 for count in range(size): t.color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) t.forward(50) t.stamp() t.backward(20) t.left(45) t.forward(20) t.backward(20) t.right(90) t.forward(20) t.backward(20) t.left(45) t.backward(30) t.left(360/size) return | |
function call: snowflake() |
def snowflake_parameters(length, number_of_rays, colour): for count in range(number_of_rays): t.color(colour) t.forward(length) t.stamp() t.backward(length/3) t.left(45) t.forward(length/3) t.backward(length/3) t.right(90) t.forward(length/3) t.backward(length/3) t.left(45) t.backward(length*(2/3)) t.left(360/number_of_rays) return t.penup() t.goto(0, -100) t.pendown() for count in range (5): snowflake3(40, 10, “blue”) t.penup() t.goto(random.randint(-100, 100), random.randint(-100, 100)) t.pendown() snowflake3(15, 6, “violet”) t.penup() | |
t.goto(random.randint(-100, 100), random.randint(-100, 100)) t.pendown() |