Practice · Python

Practice if / else

Branch execution with if/else and simple ternary expressions based on a boolean condition.

if / elsewarming python…

Classify Song Tempo

Write a function classify_tempo(bpm) that receives an integer representing the beats per minute (BPM) of a song. It should return:

  • "slow" if the BPM is less than 60,
  • "moderate" if the BPM is between 60 and 120 inclusive,
  • "fast" if the BPM is greater than 120.

Examples

classify_tempo(45)   # returns "slow"
classify_tempo(90)   # returns "moderate"
classify_tempo(150)  # returns "fast"
Press Run to see output, or Check to grade against the tests.

Want a whole course built around if / else?

Start my path — free

Adaptive practice, streaks, projects with real code review. Free tier gates AI help, never content.

Practice Python: if / else — CodeArcade