Skip to main content

Section 2.15 Unit 2 Loops Project

45 minutes
This project was designed by Leigh Anne Fitz of Virginia Beach City Public Schools and the autograding tests were designed by Kate McDonnell of Cherry Creek Schools in Colorado.

Subsection 2.15.1 Seven-Day Fitness Challenge

Your school is running a Seven-Day Fitness Challenge. Students will enter the number of minutes they exercised each day for one week. The program will analyze their activity and determine whether they met their daily goals. Create a Python program that helps a student track their exercise for one week.
For each of the 7 days, the program should:
  1. Ask the user how many minutes they exercised.
  2. Verify that the number entered is valid.
  3. Determine the student’s activity level for that day.
  4. Display the result.
  5. Keep track of the total exercise minutes.
At the end of the week, the program should calculate the student’s average daily exercise time and provide an overall assessment.
Table 2.15.1. Activity Levels
Daily Exercise Minutes Activity Level
0 - 19 Needs Improvement
20 - 39 Good
40 - 59 Great
60 or more Excellent
For example:
Day 1: 45 minutes

Activity Level: Great
Input Validation: Exercise minutes must be between 0 and 300. If the user enters an invalid value, the program should continue asking until a valid value is entered. For example:
How many minutes did you exercise? -20

Please enter a value between 0 and 300.

How many minutes did you exercise? 400

Please enter a value between 0 and 300.

How many minutes did you exercise? 35

Activity Level: Good
Overall Weekly Assessment: At the end of the week, determine an overall assessment based on the student’s average daily exercise time.
Table 2.15.2. Overall Assessment
Average Daily Minutes Assessment
Less than 20 Keep Working!
20 - 39 Good Job!
40 - 59 Great Work!
60 or more Fitness Champion!
Sample Output:
========================================
       SEVEN-DAY FITNESS CHALLENGE
========================================

Day 1: 30 minutes

Activity Level: Good


Day 2: 45 minutes

Activity Level: Great


Day 3: 15 minutes

Activity Level: Needs Improvement


Day 4: 60 minutes

Activity Level: Excellent


Day 5: 40 minutes

Activity Level: Great


Day 6: 25 minutes

Activity Level: Good


Day 7: 50 minutes

Activity Level: Great


========================================
             WEEKLY SUMMARY
========================================

Total Exercise Minutes: 265

Average Daily Minutes: 37.86

Overall Assessment: Good Job!

========================================

Project 2.15.1 Seven-Day Fitness Challenge.

Create a Python program that helps a student track their exercise for one week. The program should use a loop to ask for the number of exercise minutes for each of 7 days, validate each entry, determine the activity level for each day, keep track of the total exercise minutes, calculate the average daily exercise time, and provide an overall assessment.
Exercise minutes must be between 0 and 300. Use a while loop to continue asking for a valid value when the user enters an invalid number.

Subsection 2.15.2 Project Reflection

Activity 2.15.2 Project Reflection: Iteration.

Consider the first iteration statement in your project code above (the for loop). Identify the loop variable by writing it below. Identify the number of times the body of your iteration statement will execute. Explain how a for loop using range cannot cause an infinite loop.

Activity 2.15.3 Project Reflection: Loops and Input Validation.

Describe how you used a while loop to validate input. What happened when the user entered an invalid value? How did you test your program to make sure that invalid values were rejected and valid values were accepted? Describe a condition or error that would cause your iteration statement to not terminate and cause an infinite loop.
You have attempted of activities on this page.