CPTR 124 Fundamentals of Programming
This lab introduces conditional execution.
Forming a TeamYou are encouraged to choose a partner from this class as a teammate. You two will work together on this assignment.
You are not required to work with someone else; you may work alone if you prefer.
Familiarize yourself with the assignment
Read over the complete lab before you begin writing your program.
HousekeepingYou will write two separate Python programs. Name your source files
What to doWrite Python programs to solve the following two problems:
- Maximum of Five
Write a program that allows the user to enter in exactly five integer values. The program then should print the largest of the five values entered. You may not use any built-in library routines, except for
input; you must use conditional statements. A sample run is shown here:Please enter five integer values Number 1: 20 Number 2: -1 Number 3: 6 Number 4: 31 Number 5: 19 The maximum is 31
(The 20, –1, 6, 31, and 19 correspond to user input; the program is responsible for the rest of the output.)
Even if there is a tie for the maximum value, just print the maximum once.
Hint: You can use fairly complicated conditional expressions involving
and's, etc., or you can use very simple conditional expressions. If want to implement the simpler logic, you can introduce an additional variable and use four very simple, sequential
ifstatements. The tradeoff of an extra variable for the greatly simplified logic is a good one.
- Body Mass Index
The body mass index (BMI) is a measure of relative weight. It takes into account both height and weight in an attempt to determine if a person is underweight, normal weight, or overweight. BMI often is used to estimate a person's risk of health problems. BMI is easy to compute:
where mass is a person's mass in kilograms, and height is the person's height in meters.
Write a program that requests a person's weight in pounds and height in feet and inches. The program then should print the person's BMI and then report the person's classification according to the following table:
BMI < 18.5
18.5 ≤ BMI < 25
25 ≤ BMI < 30
BMI ≥ 30
Note that you must convert pounds to kilograms and feet and inches to meters before performing the computation. 1 pound = 0.454 kilograms, 12 inches = 1 foot, and 1 inch = 0.0254 meters.Please enter your weight in pounds: 150 Next, enter your height in feet and inches . . . Enter feet: 5 Enter inches: 10 Your BMI is 21.541879818453516 Your classification is NORMAL WEIGHT
Your output should be formatted to look like the sample run above.
- Maximum of Five
I will review your lab with you before you leave. Be prepared to answer questions about any parts of your program. After you have been checked out, please submit your two Python source files (the
bmi.pyfiles) to http://eclass.e.southern.edu.
Don't forget to log out on your lab workstation and take your USB drive before you leave the lab.