241. Python Program to Make a Weekly Step Counter
EasyPhase 1 · Warm-up
This one uses split(), a for loop and if. You have used all three before.
Overview
Fitness watches and phone apps count your steps every day. At the end of the week, they show a short summary of your walking.
Problem Statement
Ravi wants a summary of a week of walking. Ravi writes the steps for the 7 days on one line, with a space between the numbers. Day 1 is the first number and day 7 is the last.
Read the line. Print the total steps, the average steps per day with 2 decimal places, and the number of the best day: the day with the most steps. If two days tie for the most steps, the best day is the first of them. Use this format:
Total: <total>
Average: <average>
Best day: <day>
Steps
- Read the line and split it into 7 pieces.
- Loop over the 7 days. Turn each piece into a whole number and add it to the total.
- In the same loop, keep the most steps so far and its day number. Change them only when a day has more steps.
- Work out the average: the total divided by 7.
- Print the 3 lines.
Examples
Example 1. Input 8000 7000 9500 6000 8000 10000 4000 gives:
Total: 52500
Average: 7500.00
Best day: 6
Why: the 7 numbers add up to 52500, and 52500 ÷ 7 = 7500. The most steps, 10000, are on day 6.
Example 2. Input 5000 9000 7000 9000 6000 8000 6000 gives:
Total: 50000
Average: 7142.86
Best day: 2
Why: 50000 ÷ 7 = 7142.857..., which shows as 7142.86. Day 2 and day 4 both have 9000 steps, and day 2 comes first.
Input
One line of 7 whole numbers (0 or more), with one space between them. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
Three lines: Total: <total>, Average: <average> with 2 decimal places, and Best day: <day> with a day number from 1 to 7. The tests try 6 different inputs, also a week of only zeros.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.