Challenge: Building a Progress Tracker Using if-elif-else Statements
Task
Swipe to start coding
You're building a fitness challenge tracker that categorizes the user's effort based on their total weekly exercise time. The program should determine the correct category and provide appropriate feedback.
- Use an
if-elif-else
structure to categorize the user's exercise time efficiently. - Assign
"Super Achiever"
if the user exercises for more than 10 hours in a week. - Assign
"Hard Worker"
if the user exercises for 6 to 10 hours, inclusive. - Assign
"Getting There"
if the user exercises for at least 3 hours but less than 6 hours. - Assign
"Needs Improvement"
if the user exercises for less than 3 hours. - Store the appropriate category in a variable
title
for later use. - Ensure all
if
,elif
, andelse
statements end with a colon (:
).
Solution
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
exercise_time = 8 # Example value for total exercise time in hours
title = ""
if exercise_time > 10:
title = "Super Achiever"
elif exercise_time >= 6:
title = "Hard Worker"
elif exercise_time >= 3:
title = "Getting There"
else:
title = "Needs Improvement"
# Testing
print("Your fitness level:", title)
Everything was clear?
Thanks for your feedback!
Section 3. Chapter 4
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
exercise_time = 8 # Example value for total exercise time in hours
title = ""
___
title = "Super Achiever"
___
title = "Hard Worker"
___
title = "Getting There"
___
title = "Needs Improvement"
# Testing
print("Your fitness level:", title)
Ask AI
Ask anything or try one of the suggested questions to begin our chat