01 Checkpoint: Review Python
Purpose
Write a Python program that gets input from a user, uses variables, performs arithmetic, and displays results for the user to see.
Problem Statement
When you physically exercise to strengthen your heart, you should maintain your heart rate within a range for at least 20 minutes. To find that range, subtract your age from 220. This difference is your maximum heart rate per minute. Your heart simply will not beat faster than this maximum (220 − age). When exercising to strengthen your heart, you should keep your heart rate between 65% and 85% of your heart’s maximum rate.
Assignment
Write a Python program named heart_rate.py
that asks
for a person’s age and computes and outputs the slowest and fastest
rates necessary to strengthen his heart. To start your program, copy
and paste the following code into your program and use it as an
outline as you write code. Note that in a Python program, a triple
quoted string at the top of the file acts as a comment for the
entire program.
""" When you physically exercise to strengthen your heart, you should maintain your heart rate within a range for at least 20 minutes. To find that range, subtract your age from 220. This difference is your maximum heart rate per minute. Your heart simply will not beat faster than this maximum (220 - age). When exercising to strengthen your heart, you should keep your heart rate between 65% and 85% of your heart’s maximum rate. """
Helpful Documentation
The preparation content for this lesson explains how to write code to do the following:
- Get input from a user
- Convert user input from a string to a number
- Display results for the user to see
Testing Procedure
Verify that your program works correctly by following each step in this testing procedure:
- Run your program and enter the input shown below. Ensure that your program’s output matches the output below.
> python heart_rate.py Please enter your age: 23 When you exercise to strengthen your heart, you should keep your heart rate between 128 and 167 beats per minute.
- Run your program using your age or the age of one of your parents. Use a calculator to ensure that the output is correct.
Sample Solution
When your program is finished, view the sample solution for this assignment to compare your solution to that one. Before looking at the sample solution, you should work to complete this checkpoint program. However, if you have worked on it for at least an hour and are still having problems, feel free to use the sample solution to help you finish your program.
Ponder
During this assignment, you wrote a Python program that gets input from a user, uses variables, performs arithmetic, and displays results for the user to see. Because you should have learned how to write this type of program in CSE 110, this assignment should have been fairly easy for you. If this assignment was difficult for you, you should review the concepts from CSE 110 and the programs that you wrote in that course.
Submission
When complete, report your progress in the associated I‑Learn quiz.