Skip to content

Commit 034e9c1

Browse files
committed
Add magic numbers to environment
1 parent 03c3235 commit 034e9c1

File tree

7 files changed

+34
-13
lines changed

7 files changed

+34
-13
lines changed

brain_games/games/calc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import random
22

3+
MIN_NUMBER = 1
4+
MAX_NUMBER = 20
5+
OPERATIONS = ["+", "-", "*"]
6+
37
TASK = "What is the result of the expression?"
48

59

610
def get_round():
7-
num1 = random.randint(1, 20)
8-
num2 = random.randint(1, 20)
9-
op = random.choice(["+", "-", "*"])
11+
num1 = random.randint(MIN_NUMBER, MAX_NUMBER)
12+
num2 = random.randint(MIN_NUMBER, MAX_NUMBER)
13+
op = random.choice(OPERATIONS)
1014

1115
match op:
1216
case "+":

brain_games/games/even.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import random
22

3+
MIN_NUMBER = 1
4+
MAX_NUMBER = 100
5+
36
TASK = 'Answer "yes" if the number is even, otherwise answer "no".'
47

58

@@ -8,7 +11,7 @@ def is_even(number: int) -> bool:
811

912

1013
def get_round():
11-
number = random.randint(1, 100)
14+
number = random.randint(MIN_NUMBER, MAX_NUMBER)
1215
question = str(number)
1316
correct_answer = "yes" if is_even(number) else "no"
1417
return question, correct_answer

brain_games/games/gcd.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import math
22
import random
33

4+
MIN_NUMBER = 1
5+
MAX_NUMBER = 100
6+
47
TASK = "Find the greatest common divisor of given numbers."
58

69

710
def get_round():
8-
num1 = random.randint(1, 100)
9-
num2 = random.randint(1, 100)
11+
num1 = random.randint(MIN_NUMBER, MAX_NUMBER)
12+
num2 = random.randint(MIN_NUMBER, MAX_NUMBER)
1013

1114
question = f"{num1} {num2}"
1215
correct_answer = str(math.gcd(num1, num2))

brain_games/games/prime.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import random
22

3+
MIN_NUMBER = 1
4+
MAX_NUMBER = 100
5+
36
TASK = 'Answer "yes" if given number is prime. Otherwise answer "no".'
47

58

@@ -17,7 +20,7 @@ def is_prime(n: int) -> bool:
1720

1821

1922
def get_round():
20-
number = random.randint(1, 100)
23+
number = random.randint(MIN_NUMBER, MAX_NUMBER)
2124
question = str(number)
2225
correct_answer = "yes" if is_prime(number) else "no"
2326
return question, correct_answer

brain_games/games/progression.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import random
22

3+
MIN_LENGTH = 5
4+
MAX_LENGTH = 10
5+
MIN_START = 1
6+
MAX_START = 20
7+
MIN_STEP = 1
8+
MAX_STEP = 10
9+
HIDDEN_PLACEHOLDER = ".."
10+
311
TASK = "What number is missing in the progression?"
412

513

@@ -8,15 +16,15 @@ def make_progression(start, step, length):
816

917

1018
def get_round():
11-
length = random.randint(5, 10) # длина от 5 до 10 включительно
12-
start = random.randint(1, 20)
13-
step = random.randint(1, 10)
19+
length = random.randint(MIN_LENGTH, MAX_LENGTH)
20+
start = random.randint(MIN_START, MAX_START)
21+
step = random.randint(MIN_STEP, MAX_STEP)
1422

1523
progression = make_progression(start, step, length)
1624
hidden_index = random.randint(0, length - 1)
1725

1826
correct_answer = str(progression[hidden_index])
19-
progression[hidden_index] = ".."
27+
progression[hidden_index] = HIDDEN_PLACEHOLDER
2028
question = " ".join(map(str, progression))
2129

2230
return question, correct_answer

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.8.0"
3+
version = "0.9.0"
44
description = "«Игры разума» — набор из пяти консольных игр"
55
readme = "README.md"
66
authors = [

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)