Skip to content

Commit fdbe8c7

Browse files
committed
Add prime.py, brain_prime.py
1 parent 5e4609e commit fdbe8c7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

brain_games/games/prime.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from brain_games.engine import run_game
2+
from brain_games.utils import get_random_num
3+
from brain_games.consts import PRIME_INSTRUCTION
4+
5+
6+
def is_prime(num):
7+
deviders_num = 0
8+
square_root = int(num ** (1/2))
9+
for i in range(2, square_root + 1):
10+
if num % i == 0:
11+
deviders_num += 1
12+
return deviders_num == 0
13+
14+
15+
def get_num_and_answer():
16+
num = get_random_num()
17+
correct_answer = 'yes' if is_prime(num) else 'no'
18+
return num, correct_answer
19+
20+
21+
def run_prime_game():
22+
run_game(get_num_and_answer, PRIME_INSTRUCTION)

brain_games/scripts/brain_prime.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from brain_games.games.prime import run_prime_game
2+
3+
4+
def main():
5+
run_prime_game()
6+
7+
8+
if __name__ == "__main__":
9+
main()

0 commit comments

Comments
 (0)