Skip to content

Commit 9d2c253

Browse files
committed
Переписана игра prime
1 parent 2505e4a commit 9d2c253

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

brain_games/games/prime.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import random
22
rules = 'Answer "yes" if given number is prime. Otherwise answer "no".'
3+
def is_prime(n):
4+
if n < 2:
5+
return False
6+
for i in range(2, int(n ** 0.5) + 1):
7+
if n % i == 0:
8+
return False
9+
return True
10+
311
def get_round():
412
num = random.randint(1, 50)
513
question = f'Question: {num}'
6-
for i in range(1, num):
7-
if num % i == 0 and i != num and i != 1:
8-
correct_answer = 'no'
9-
break
10-
else:
11-
correct_answer = 'yes'
14+
correct_answer = 'yes' if is_prime(num) else 'no'
1215
return question, correct_answer

poetry.lock

Lines changed: 0 additions & 17 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "hexlet-code"
3-
version = "0.6.2"
3+
version = "0.6.3"
44
description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.10"

0 commit comments

Comments
 (0)