Download presentation
Presentation is loading. Please wait.
Published bySelma Møller Modified over 6 years ago
1
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
You had the function square(), which draws a square of side length of 100 pixels. Write instructions in the left hand side of the box corresponding the operation that you need to perform on the right. def square(): # import turtle package # create and name a turtle # advance ____ by 100 # turn _____ right by 90o # turn ___ right by 90o
2
Square Function In the same file, write another function, square1(), that draws a square of side lengths 100, but in a for loop (and make it sure that you call the function to execute). Copy square2() and paste in the same file, and rename it spiral1(). In spiral1(), change the angle from 90 to 91 degree, and have the turtle draw for 100 times. A list (Chap. 4) is useful to keep several values to be reused. Copy and paste spiral1() and rename it spiral2(). Instead of .forward(), used .circle() to draw circles for 100 times. Prior to the ‘for’ loop, add the instruction, ‘colors = [“red”, “yellow’, “blue”,”green”].’ Inside the ‘for’ loop, add the instruction, ‘___.color = colors[ x %4]’ where x is the variable you use for the ‘for’ loop.
3
Rosette Function Copy square1() and paste in the same file, and rename it rosette1(). In resette1(), change .forward(100) function to .circle(100). You have four-circle rosette pattern. Copy rosette1() and paste in the same file, and rename it rosette2(). In resette2(), modify the program so that you draw 6 circles. Copy rosette2() and paste in the same file, and rename it rosette3(). In resette3(), modify the program so that you draw 30 circles.
4
Lab 0926 Modify rosette3() function so that colors of circles are changed among six colors. your Python program to
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.