Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Simplifying Fitness Tracker Logic | Mastering Python if Statements
Conditional Statements in Python

book
Challenge: Simplifying Fitness Tracker Logic

Task

Swipe to start coding

You're building a fitness tracker app that provides motivational messages when users reach their fitness goals. Currently, the logic is cluttered with multiple if statements, and it's your job to simplify it.

  • Combine the two conditions into a single if statement.
  • Use the or operator to check if at least one of the conditions is met.
  • Ensure result_message is updated only once inside the if block.

Solution

steps_taken = 12000
step_goal = 10000
calories_burned = 350
calorie_goal = 500

result_message = False

if steps_taken >= step_goal or calories_burned >= calorie_goal:
result_message = True
print("Great job, you've reached at least one goal")
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 6
steps_taken = 12000
step_goal = 10000
calories_burned = 350
calorie_goal = 500

result_message = False

if steps_taken >= step_goal:
result_message = True
if calories_burned >= calorie_goal:
result_message = True

if result_message:
print("Great job, you've reached at least one goal")
toggle bottom row
some-alt