This project is designed to reinforce some of the concepts we have learned from Chapter 1 of our textbook. I recommend for you to read Chapter 1 before getting started.
You are to do this project individually.
IDLE is already installed on the lab computers. If you want to install IDLE on your own laptop, please follow the instructions on the links page. You can start an IDLE session by clicking on the icon; the Python shell should now appear.
In the IDLE session, write and evaluate Python expressions corresponding to the following statements:
Up until now, you have been typing commands in the Python shell. For this task, you are going to write functions in a new file window and then call them in the Python shell.
Please note that all the variable names you use in your functions 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
lawn.py
.
Please be cautious of two things, first, there is a difference between a function that returns an answer and a function that simply prints it out. (Professor Yu should have talked about this in class, if you are still not sure, ask professor Yu or look at your lecture notes.) Second, for this part of the task the time it takes for you to mow a lawn can be a floating point number. (For example, taking 2.3 hours to mow a lawn is completely fine.)
timeToMow
function out.
Specifically, use the timeToMow
function to calculate how much time it would take
to mow a lawn that is 120 feet in depth and 210 feet in width. Make sure that your function gives the correct answer; if not, fix it. Cut 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 120 feet in depth and 210 feet in width) from the Python shell
underneath the corresponding question (Task 3, question 2) in the template.
lawn.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. Cut 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) in the template.
roundedTimeToMow
function to construct this table.
Please be cautious of two things, first, you should use roundedTimeToMow
to calculate how long
it will take to mow a lawn of particular depth. Second, you should use a for loop to print out the table. You can do this by typing a for loop in the Python shell or by
writing another function in lawn.py
consisting of a for loop. Be sure to check your result. Cut and paste the input
(the command you typed in the Python shell, which may just be running a function you wrote in lawn.py".
The function definition, if there is one, is going to be submitted in lawn.py and hence doesn't need to be in the project1a.txt file.)
and output (your table) underneath the corresponding question (Task 3, question 5) in the template.
                   
             
Note: for these two pictures, the size of each polygon is not important (you can make them any sizes). You must also use a for loop to draw each of the polygons.
Note: the size of the three circles is not important either; their centers should be, more or less, the points of an equilateral triangle...
There are several ways to draw these pictures. We recommend the following method:
drawPolygon
and drawCircle
functions
on page 38 and 40 of your textbook). extraCredit.doc
.
Hint: for the last picture, you will need to use other functions from the cTurtle
library, ones that we will not mention in class.
Look at Appendix C of your textbook for various function from the cTurtle
library and try them out (if you have a second-edition textbook, your
Appendix C describes the similar turtle
library instead. You will have fewer difficulties if you use the cTurtle
library instead).
If you are stuck, ask your lab instructor for help.
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 the following 2 - 3 files (with these recommended names):
timeToMow
and roundedTimeToMow
.
If you had wrote a function for Task 4 number 5, you should include it as well.
You will earn one point for each of the following accomplishments. A minor error results in a 1/2 deduction.
You gave the correct python expression for Task 1 question 1.
You gave the correct python expression for Task 1 question 2.
You gave the correct python expression for Task 1 question 3.
You gave the correct python expression for Task 1 question 4.
You gave the correct python expression for Task 1 question 5.
You gave the correct assignment statement for Task 2 question 1.
You gave the correct assignment statement for Task 2 question 2.
You gave the correct assignment statement for Task 2 question 3.
You gave the correct assignment statement for Task 2 question 4.
You used the correct notation to define a function called timeToMow
. The function has two parameters.
Your timeToMow
function correctly calculates the time it will take to mow a lawn of certain depth and width.
Your timeToMow
function returns an answer.
Your input and output for Task 3 number 2 are correct.
You used the correct notation to define a function called roundedTimeToMow
. The function has one parameter.
Your roundedTimeToMow
function use the one parameter to correctly calculate the width of a lawn.
Your roundedTimeToMow
use the timeToMow
function to correctly calculate the exact time to mow a lawn.
Your roundedTimeToMow
function returns an answer and correctly rounds the returned answer to an integer.
Your input and output for Task 3 number 4 are correct.
For Task 3 number 5, you used a for loop to construct the table. The starting size, ending size, and step size of your for loop are correct.
For Task 3 number 5, the body of your for loop uses roundedTimeToMow
.
For Task 3 number 5, the body of your for loop prints two columns of correct data.
Extra credit: you wrote the correct code to draw picture # 1 (the 5 sided polygon); a 1/2 point deduction for a minor error (such as not using a for loop in your implementation or not including the input and output)
Extra credit: you wrote the correct code to draw picture # 2 (the 7 sided polygon); a 1/2 point deduction for a minor error (such as not using a for loop in your implementation or not including the input and output)
Extra credit: you wrote the correct code to draw picture # 3 (the 3 circles); a 1/2 point deduction for any minor error (such as not including the input and output)