Use the turtle to draw flower-like shapes composed of many squares.
This lab is for the assessment of two competencies:
I’m assuming you’re logged into merlin through X2Go. Since you’re going to be drawing flowers, you need a graphical session, such as X2Go provides; you cannot do this assignment with text-only tools such as PuTTY. Alternatively, you can also get a graphical session (but not desktop) using Macintosh XQuartz: in the terminal, enter the command
ssh -Y USER@merlin.iue.edu
where USER is your IU username.
In your X2Go session, open a terminal (Applications menu / System tools / Terminal).
In the terminal, give this command
$ idle3 &($ is the shell prompt, so don’t type it) to launch Python3’s IDLE.
In the IDLE window “Python Shell,” you have a Python interpreter. Use it for testing as you develop your program, but don’t type your definitions in it, because you cannot save them from there in a useful form. Use its File menu to create a “New File” or “New Window” and put definitions in the new file window. When you’re ready to test, use the new window’s Run menu / “Run module.” This loads your definitions into the Python shell, and there you can test them.
Alternatively, you can use the terminal or the applications menu to launch a different text editor (gedit, emacs, vi, nano, etc.), type your definitions in the text editor, save the file (say, lab1.py), and then run Python in the terminal like this:
$ python3 -i lab1.pyThe -i flag means “interactive,” so that Python waits for your commands after reading and executing the file. If you want Python to execute the file and then quit, omit the -i.
When you have tested your program to your satisfaction and are ready to take screenshots, you should probably not use IDLE for this. There are some weird interactions between IDLE and the Turtle graphics window that can make your flower disappear when you try to take its picture. For a work-around, see the Testing instructions below.
Follow directions in Programming Exercise 1.1 on page 44.
The function name must be named drawflower.
The drawflower function must have two arguments, although the directions explicitly mention only one of these.
numSquares, which actually means the number of petals, since each petal is drawn as a square.The drawflower function must use a loop: a for loop which repeats numSquares times.
You must define the drawSquare function. You may copy either of two versions from the textbook. But the looping version is better, don’t you think?
The drawflower function must call the drawSquare function.
The drawflower function must draw a flower, as specified in the exercise.
In testing, you must call the drawFlower function with the proper arguments.
Read and observe all the style rules given in the Coding Standards for Chapter 1 (header comments, imports, docstrings, white space, meaningful identifiers, indenting, line length).
In Canvas Assignments, turn in your Python source file and three screenshots showing the result of drawflower with three different values of numSquares > 5. See below for Testing instructions.
drawSquare function presented in the chapter. Two versions of this function are presented, in Listing 1.2 and Listing 1.3. Copy the code for either version into your file.numSquares means the number of petals.numSquares petals, the turtle must turn a total of 360 degrees in numSquares turns. A simple division will tell you the angle for each turn.These drawings don’t look very flowery with less than 5 petals, but here’s how mine looks with numSquares = 5:

Your drawing doesn’t have to look exactly like mine. I’m just showing this example to emphasize that the flower drawing is not expected to be very artistic: it doesn’t have to be any better than this.
For screenshot instructions, see How to Capture a Screenshot in A Guide to Linux at IU East.
If you run your program in IDLE (or IDLE3), you might have some difficulty with the drawing window, either when you try to take a screenshot or even before that. To avoid this, test your program in the terminal. Here’s how I tested mine:
$ python3 -i flower.py
>>> drawflower(g, 5)
>>> g.reset()
>>> drawflower(g, 23)
>>> g.reset()
>>> drawflower(g, 12)
>>> quit()
$
The -i flag means run Python interactively: load the file, but wait for commands. g was the variable in flower.py representing my Turtle. After each screenshot I used g.reset() to clear the drawing window.
lab7.py or flower.py; or possibly something else, but it should definitely end with .py..png) and JPEG (extension .jpg) image files are automatically approved. Before submitting any other image file format, ask the instructor. Macintosh TIFF files are sometimes too large; please convert them to PNG before submitting.drawflower, with two arguments; your testing must properly call this function; and the program must properly define and call the function drawSquare. for loops. For full credit, the program must draw squares in a loop which repeats the number of times requested in the numSquares parameter of the drawflower function. TOTAL: 20 POINTS