As usual, create two directories for today's class. Create a
directory called lecture6
under activities, and
a directory called lab6
under labs.
Modules are extensions of functionality for Python. They allow us to
select new functionality that was previous unavailable to us. Two
modules we will learn about today are math
and
turtle
.
These modules define constants and functions. These functions allow for the abstraction of behavior, which can allow us to do some really cool things.
The turtle module allows us to draw things to the screen. Using the
turtle module, write a program called square.py
that
uses the turtle module to draw a square to the screen.
Functions are a way for us to give a name to some block of code. Not only can this improve readability, but now we can re-use code much easier than copying and pasting.
Functions do change the order in which things get interpreted and executed.
Write a function that draws a square from the current location of the turtle object. Use this function to draw 4 squares on the window, as shown below.
Body mass index (BMI) is a measurement devised in the 1800's, as a way of analyzing an individuals body shape, as it relates to their height in weight. While the values and benefits of such analysis is hotly contested, generally speaking a "normal" BMI is in the range 18.5 to 25.
In a file called bmi.py
, create a function
bmi
, for computing
BMI using values when given metric values. This function should use
input to get information from the user, and print
the calculated BMI. The BMI of a person is computed by dividing a
person's weight (in kilograms) by the square of the person's height
(in meters).
Your functions should be properly commented, and should use meaningful names for values and simple statements to make the program more readable. Make sure to include a comment header which lists who the authors are, as well as the purpose of the file.
When you have finished, create a tar file of your lab6
directory. To submit your activity, go to cseval.roanoke.edu. You should
see an available assignment called Lab Assignment 6
. Only
one of your pair should submit your activity. Make sure both partners
are listed in the header of your file.
Do not forget to email your partner todays files!