CS21 Lab 3: if/else statements

Due Saturday (Sept 26) before midnight

This lab assignment requires you to write a few programs. First, run update21. This will create the cs21/labs/03 directory and copy over any starting-point files for your programs. Next, move into your cs21/labs/03 directory and begin working on the Python programs for this lab. The pwd command helps you verify that you are in the correct sub-directory.

$ update21
$ cd cs21/labs/03
$ pwd
We will only grade files submitted by handin21 in this directory, so make sure your programs are in this directory!

Programming tips

As you write your programs, use good programming practices:

1. VO2 max calculator

Write a program that asks the user for some data, then computes the user's VO2 max, using the Rockport Fitness Walking Test equation:

$$\mathrm{VO_2\; max} \approx 132.853 - (0.0769 \times \text{body weight (lbs)}) - (0.3877 \times \text{age} ) + $$ $$(6.3150 \times \text{gender}[\text{female} = 0, \text{male} = 1]) - (3.2649 \times \text{mile time} ) - (0.1565 \times \text{heart rate on completion})$$

Your program should prompt the user to enter the above data (weight, age, gender, mile time, and heart rate), then output the calculated VO2 max and a rating, based on the following chart:

VO2 max values for 20-29 year olds
Very PoorPoorFairGoodExcellentSuperior
Females< 23.623.6-28.929.0-32.933.0-36.937.0-41.0> 41.0
Males< 33.033.0-36.436.5-42.442.5-46.446.5-52.4> 52.4

Note: to simplify the program, we assume the user is in the 20-29 year old age range. You can also assume the user always enters valid input data.

Here are some sample runs showing how your program should work:

$ python VO2max.py
body weight (lbs): 160
        age (yrs): 20
     gender (m/f): m
  mile time (min): 18
 heart rate (b/m): 130

 VO2max = 40.00 .... Fair
$ python VO2max.py
body weight (lbs): 160
        age (yrs): 20
     gender (m/f): f
  mile time (min): 15
 heart rate (b/m): 100

 VO2max = 48.17 .... Superior

And here's an online calculator if you want to test your program against other numbers: http://www.brianmac.co.uk/rockport.htm

2. five-question quiz

Write a program, 5qquiz.py that asks the user 5 yes/no questions. An example run of the program might look like the following:

$ python 5qquiz.py

 1. The Eagles will win the superbowl this year....... [Y/n] y
>>>>>>> CORRECT!

 2. rm is the UNIX command to remove a file........... [Y/n] <Enter>
>>>>>>> CORRECT!

 3. Barack Obama is the 45th PotUS.................... [Y/n] y
>>>>>>> wrong answer

 4. Jupiter is the 4th planet from the Sun............ [Y/n] n
>>>>>>> CORRECT!

 5. vim is better than emacs.......................... [Y/n] y
>>>>>>> CORRECT!

You got 4 out of 5 correct!
Not bad.

Here are the requirements for this program:

3. counting vowels

Write a program called countvowels.py that asks the user for an input string and then counts how many total vowels are present in the given string. Here are some examples:

$ python countvowels.py
input string: we LOVE computer science!!
There are 9 vowels in that string.
$ python countvowels.py
input string: HI!!!!!!!
There is 1 vowel in that string.
$ python countvowels.py
input string: aeiouxyzAEIOUXYZ
There are 10 vowels in that string.

4. secret message

In the starter file message.py, a very large string is assigned to the variable msg. Hidden in that string is a secret message. Your job is to find and print the hidden message.

The letters of the hidden message are evenly spaced throughout the long string. The spacing is given by the number of a's in the string. So, to find the hidden message, your first task is to figure out how many a's are in the string. Once you have that number, use it to find the message.

Here's a small example:

msg = "ssauzatfeiqrbajqrsxwax"

Counting through that string, you'll find that there are 4 a's. To find the message, start at position 4 (since there are 4 a's) and then use every 4th character (since there are 4 a's). So, here is the secret message:

msg = "ssauzatfeiqrbajqrsxwax"

The only requirements for the program are that you don't use advanced python concepts (ones we haven't covered in class yet), and that your program finds and prints the hidden message.


Remember you may run handin21 as many times as you like. Each time you run it new versions of your files will be submitted. Running handin21 after you finish a program, after any major changes are made, and at the end of the day (before you log out) is a good habit to get into.