dmi-sm/python-project-49

View on GitHub
brain_games/games/prime.py

Summary

Maintainability
A
0 mins
Test Coverage
from random import randint

GAME_RULE = 'Answer "yes" if given number is prime. Otherwise answer "no".'


def is_prime(task):
    if task < 2:
        return False
    for _ in range(2, (task // 2) + 1):
        if task % _ == 0:
            return False
    return True


def get_question_and_answer():
    task = randint(0, 10)
    answer = 'yes' if is_prime(task) is True else 'no'
    return (task, answer)