Practice · Python

Practice for Loops & range()

Iterate a fixed number of times or over a range with for, choosing start/stop/step correctly.

for Loops & range()warming python…

Sum Beats Above Threshold

Write a function total_beats(durations, min_beat) that receives a list of integer beat lengths of musical notes and an integer min_beat. Return the sum of all beats that are at least min_beat. If no beats meet the criterion, return 0.

Examples

total_beats([1, 3, 5, 2], 3)  # returns 8 (3+5)
total_beats([], 4)            # returns 0
Press Run to see output, or Check to grade against the tests.

Want a whole course built around for loops & range()?

Start my path — free

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