Lab 7: Drawing Flowers - INFO-I210

Overview

Use the turtle to draw flower-like shapes composed of many squares.

This lab is for the assessment of two competencies:

Starting Python

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.

  1. In your X2Go session, open a terminal (Applications menu / System tools / Terminal).

  2. In the terminal, give this command

    $ idle3 &

    ($ is the shell prompt, so don’t type it) to launch Python3’s IDLE.

  3. 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.

  4. 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.py

    The -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.

Requirements

Follow directions in Programming Exercise 1.1 on page 44.

  1. The function name must be named drawflower.

  2. The drawflower function must have two arguments, although the directions explicitly mention only one of these.

    1. The first argument is the Turtle, as in most of the examples in Chapter 1.
    2. The second argument is called numSquares, which actually means the number of petals, since each petal is drawn as a square.
  3. The drawflower function must use a loop: a for loop which repeats numSquares times.

  4. 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?

  5. The drawflower function must call the drawSquare function.

  6. The drawflower function must draw a flower, as specified in the exercise.

  7. In testing, you must call the drawFlower function with the proper arguments.

  8. 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).

  9. 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.

Hints

Testing

Submission

Scoring

TOTAL: 20 POINTS