This project is designed to reinforce some of the concepts we have learned from Chapter 1 of our textbook. You should read Chapter 1 (especially the parts assigned in the pre-class reading assignments) before getting started.
You are to do this project individually.
You found a summer job mowing the lawns in your neighborhood. You would like to know how long it will take for you to mow each one of them. You can find out the dimension of each lawn, and you know that your mowing speed is two square feet per second. Finally, you know that all the lawns in your neighborhood are rectangular.
Please note that all the variable names you use in your function should be descriptive.
timeToMow
. This function should have two parameters, one for
the depth of a lawn (in feet) and one for the width of a lawn (in feet). Your functions
should return the time (in hours) it will take to mow a lawn of the corresponding depth and width. Save your program in a file called
project1.py
.
Note:
Copy and paste the commented out information at the top of the file (name, credit, description, etc.) and complete them. These should be included at the top of every submitted .py files from now on.
Copy and paste the rest of the project1template.py to the bottom of your project1.py
. You will answer a few questions underneath the corresponding labels.
timeToMow
(in item 1), you can run your program by using IDLE's "Run Module" command from the Run menu; or equivalently
by pressing the F5 key. If IDLE reports any syntax errors in your program, try fixing them. When you get past that hurdle,
use the Python shell to try your timeToMow
function out.
Specifically, use the timeToMow
function to calculate how much time it would take
to mow a lawn that is 140 feet in depth and 300 feet in width. Make sure that your function gives the correct answer; if not, fix it. Copy and paste
the input (the command you typed in the Python shell calling the timeToMow
function)
and the output (showing how long it takes to mow a lawn that is 140 feet in depth and 300 feet in width) from the Python shell
underneath the corresponding question (Task 1, question 3).
project1.py
), create another function called roundedTimeToMow
. This function should have only one
parameter, the depth of a lawn (in feet), and return the time it will take for you to mow a lawn of the corresponding depth rounded to the nearest hour.
Your definition of roundedTimeToMow
should call the timeToMow
function you previously defined, so that if you were ever to adjust
timeToMow
to reflect a different mowing speed, roundedTimeToMow
would automatically also start using the new speed.
For this task,
the time it will take to mow a lawn (in hours) can not be a floating point number. Instead, your function should return an answer that is rounded off
to the nearest integer. Python has a function called round
for doing the rounding.
For example, round(2.4)
evaluates to 2, whereas round(2.6)
evaluates to 3. Insert an appropriate invocation
of the round
function
so that the answer returned from your roundedTimeToMow
function is guaranteed to be an integer.
roundedTimeToMow
to calculate the time it will take to mow a lawn that is 100 feet in depth. Make sure
that your function gives the correct answer; if not, fix it. Copy and paste the input (the command you typed in the Python shell calling the roundedTimeToMow
function)
and the output (showing how long it takes to mow a lawn that is 100 feet in depth) from the Python shell
underneath the corresponding question (Task 3, question 4) at the bottom of your file.
project1.py
, define a function printLawnTable
which takes in no input parameter. This function should print out a table showing the time it takes to mow lawns of increasing depth (given that all the lawns in the neighborhood
have the depth-to-width ratio of approximately 7 to 15).
This first row of this table should be a header with labels depth for the first column and time for the second column.
The first column of the table should show the
depth of lawns ranging from 100 feet up to, but not including, 200 feet, stepping by 10 feet each row. The second column of the table should show the corresponding time
it takes to mow a lawn of this depth.
You must use roundedTimeToMow
to calculate how long
it will take to mow a lawn of particular depth. You must also use a for loop to print out the table. You may use the print
function to display these information. Be sure to check your result.
Copy and paste the input
(the command you typed in the Python shell)
and output (your table) underneath the corresponding question (Task 1, question 6) at the bottom of your project1.py
file.
Define a function drawHendecagon
which draws a regular polygon with 11 sides when called.
This function should only take exactly one parameter, the length of the sides. You must use the turtle
module but not the cTurtle
module. You must use a for loop in the function. Hint: unlike the examples in the textbook (pages 37-39), you should create your turtle object inside of your function.
If your code is a modification of a code from our textbook or another source, remember to cite the source.
drawConcentricShapes
that draws three concentric heptagons of different sizes. This function should take no parameter. You must use the turtle
module and not the cTurtle
module. This function should create a turtle object which draws the three concentric heptagons. Your function must use a for loop. The sizes and exact placements of the heptagons do not matter, but they should be look concentric and large enough for an average person to see. They should be small enough to fit into the default-size window. The three heptagons should never touch.
Hint: some new turtle methods that you may want to use include up, down, goto
(see Table 1.3 page 25).
Call your function drawConcentricShapes
in the IDLE shell and test it.
If you have time, make the following modification to your drawConcentricShapes
function.
Add to the body of your function drawConcentricShapes
so that, the shape of your turtle is not the default arrow shape (for example, change its shape to a circle or a turtle). Hint: see Appendix C.6 page 478.
Change your function drawConcentricShapes
so that the three concentric heptagons now have three distinct colors. None of the colors should be the same as the background color, otherwise we won't be able to see the drawing. To learn more about the turtle.color
function, you can type the following lines in the prompt:
>>> import turtle
>>> help(turtle.color)
We will use this project1gradesheet.pdf when grading your lab.
You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit exactly one file (with the following name):
timeToMow
, roundedTimeToMow
, printLawnTable
, drawHendecagon
, and drawConcentricShapes
(the last one is for extra credit). This Python file should also
contain
the input and output of your functions, as instructed above. Make sure to remember to comment these out, so that your Python file can run successfully.