TGViewer
Pythonist.ru - образование по питону Pythonist.ru - образование по питону @pythonist_ru · 24K subscribers
Post #2079 3.59K
Ответ к предыдущей задаче для новичков

# calculate_even_sum.py
def calculate_even_sum(numbers):
return sum(num for num in numbers if num % 2 == 0)

# test_calculate_even_sum.py
import pytest
from calculate_even_sum import calculate_even_sum

def test_positive_numbers():
assert calculate_even_sum([1, 2, 3, 4, 5]) == 6
assert calculate_even_sum([10, 20, 30, 40, 50]) == 150

def test_negative_numbers():
assert calculate_even_sum([-1, -2, -3, -4, -5]) == -6
assert calculate_even_sum([-10, -20, -30, -40, -50]) == -150

def test_mixed_numbers():
assert calculate_even_sum([-5, 10, -3, 8, 2]) == 20
assert calculate_even_sum([0, 0, 0, 0, 0]) == 0

def test_empty_list():
assert calculate_even_sum([]) == 0

def test_no_even_numbers():
assert calculate_even_sum([1, 3, 5, 7, 9]) == 0

В этом примере функция calculate_even_sum() принимает список целых чисел и возвращает сумму только четных чисел, проверяя для этого элементы списка на четность.Тесты проверяют правильность работы функции для различных входных данных.

#задача #coding
  • 👍 7
More from @pythonist_ru
  1. Oct 1, 2026photo post
  2. Sep 28, 2026🔥 Вакансии по Python за неделю: 📥 Middle+ Python/Django-разработчик Ведомости Middle · R…
  3. Sep 22, 2026Задача с кодом. Сложное упорядочивание Упорядочивание слов в ступенчатом лексикографическо…
  4. Sep 22, 2026Бустани свою карьеру на бесплатном фесте Ozon ON! Думаешь, как попасть в топовую компанию…
  5. Sep 22, 2026photo post
  6. Sep 21, 2026🔔 Вакансии по Python за неделю: 📥 Backend Developer Python i-Line Part time · Middle · R…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →