Back to Freecodecamp

Challenge 182: 2026 Winter Games Day 3: Biathlon

curriculum/challenges/english/blocks/daily-coding-challenges-python/697a49e6ff50d756c9b6935f.md

latest1.6 KB
Original Source

--description--

Given an array of integers, where each value represents the number of targets hit in a single round of a biathlon, return the total penalty distance the athlete must ski.

  • Each round consists of 5 targets.
  • Each missed target results in a 150 meter penalty loop.

--hints--

calculate_penalty_distance([4, 4]) should return 300.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_penalty_distance([4, 4]), 300)`)
}})

calculate_penalty_distance([5, 5]) should return 0.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_penalty_distance([5, 5]), 0)`)
}})

calculate_penalty_distance([4, 5, 3, 5]) should return 450.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_penalty_distance([4, 5, 3, 5]), 450)`)
}})

calculate_penalty_distance([5, 4, 5, 5]) should return 150.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_penalty_distance([5, 4, 5, 5]), 150)`)
}})

calculate_penalty_distance([4, 3, 0, 3]) should return 1500.

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(calculate_penalty_distance([4, 3, 0, 3]), 1500)`)
}})

--seed--

--seed-contents--

py
def calculate_penalty_distance(rounds):

    return rounds

--solutions--

py
def calculate_penalty_distance(rounds):
    total_penalty = 0

    for hits in rounds:
        misses = 5 - hits
        total_penalty += misses * 150

    return total_penalty