Skip to content

Commit 72f601e

Browse files
committed
modifited gen_num
1 parent 637fffe commit 72f601e

File tree

6 files changed

+45
-36
lines changed

6 files changed

+45
-36
lines changed

brain_games/games/brain_calc.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
from random import randint, choice
2-
import brain_games.sample
1+
from brain_games.sample import gen_rand_num
2+
from brain_games.sample import samples
33

44

55
CON_ANSWER = 'What is the result of the expression?'
66

77

8-
def type_brain_calc():
8+
def type_brain_calc(numbers):
99
correct_answer = ''
10-
first_number = randint(1, 25)
11-
sec_number = randint(1, 25)
12-
arithmetic_operation = choice(['+', '-', '*'])
10+
first_number, sec_number, arithmetic_operation = numbers
1311
match arithmetic_operation:
1412
case '+':
1513
correct_answer = first_number + sec_number
@@ -22,8 +20,8 @@ def type_brain_calc():
2220

2321

2422
def main():
25-
brain_games.sample.samples(CON_ANSWER, type_brain_calc(),
26-
type_brain_calc(), type_brain_calc())
23+
samples(CON_ANSWER, type_brain_calc(gen_rand_num()),
24+
type_brain_calc(gen_rand_num()), type_brain_calc(gen_rand_num()))
2725

2826

2927
if __name__ == '__main__':

brain_games/games/brain_even.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
from random import randint
2-
import brain_games.sample
1+
from brain_games.sample import gen_rand_num
2+
from brain_games.sample import samples
33

44

55
CON_ANSWER = 'Answer "yes" if the number is even, otherwise answer "no".'
66

77

8-
def type_brain_even():
9-
first_number = randint(1, 50)
8+
def type_brain_even(numbers):
9+
first_number, sec_number, arithmetic_operation = numbers
1010
corr_ans = 'yes' if first_number % 2 == 0 else 'no'
1111
return (corr_ans,
1212
f'Question: {first_number}')
1313

1414

1515
def main():
16-
brain_games.sample.samples(CON_ANSWER, type_brain_even(),
17-
type_brain_even(), type_brain_even())
16+
samples(CON_ANSWER, type_brain_even(gen_rand_num()),
17+
type_brain_even(gen_rand_num()), type_brain_even(gen_rand_num()))
1818

1919

2020
if __name__ == '__main__':

brain_games/games/brain_gcd.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from random import randint
2-
import brain_games.sample
1+
from brain_games.sample import gen_rand_num
2+
from brain_games.sample import samples
33

44

55
CON_ANSWER = 'Find the greatest common divisor of given numbers.'
66

77

8-
def type_brain_gcd():
9-
frs_num = randint(1, 50)
10-
sec_num = randint(1, 50)
8+
def type_brain_gcd(numbers):
9+
frs_num, sec_num, arithmetic_operation = numbers
1110
re = []
1211
max_num = max(frs_num, sec_num)
1312
for i in range(1, max_num + 1):
@@ -18,8 +17,8 @@ def type_brain_gcd():
1817

1918

2019
def main():
21-
brain_games.sample.samples(CON_ANSWER, type_brain_gcd(),
22-
type_brain_gcd(), type_brain_gcd())
20+
samples(CON_ANSWER, type_brain_gcd(gen_rand_num()),
21+
type_brain_gcd(gen_rand_num()), type_brain_gcd(gen_rand_num()))
2322

2423

2524
if __name__ == '__main__':

brain_games/games/brain_prime.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from random import randint
2-
import brain_games.sample
1+
from brain_games.sample import gen_rand_num
2+
from brain_games.sample import samples
33

44

55
CON_ANSWER = 'Answer "yes" if given number is prime. Otherwise answer "no".'
66

77

8-
def type_brain_prime():
9-
num = randint(1, 50)
8+
def type_brain_prime(numbers):
9+
num, sec_number, arithmetic_operation = numbers
1010
re = []
1111
for i in range(1, num + 1):
1212
if num % i == 0:
@@ -17,8 +17,8 @@ def type_brain_prime():
1717

1818

1919
def main():
20-
brain_games.sample.samples(CON_ANSWER, type_brain_prime(),
21-
type_brain_prime(), type_brain_prime())
20+
samples(CON_ANSWER, type_brain_prime(gen_rand_num()),
21+
type_brain_prime(gen_rand_num()), type_brain_prime(gen_rand_num()))
2222

2323

2424
if __name__ == '__main__':

brain_games/games/brain_progression.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
from random import randint, choice
2-
import brain_games.sample
1+
import random
2+
from brain_games.sample import gen_rand_num
3+
from brain_games.sample import samples
34

45

56
CON_ANSWER = 'What number is missing in the progression?'
67

78

8-
def type_brain_progress():
9-
first_num = randint(1, 50)
9+
def type_brain_progress(numbers):
10+
first_num, sec_number, arithmetic_operation = numbers
1011
re = []
11-
range_progressing = randint(5, 10)
12-
sec_num = randint(1, 5)
12+
range_progressing = random.randint(5, 10)
13+
sec_num = random.randint(1, 5)
1314
for _ in range(range_progressing):
1415
re.append(str(first_num))
1516
first_num += sec_num
16-
index_replace_num = re.index(choice(re[1:]))
17+
index_replace_num = re.index(random.choice(re[1:]))
1718
replace_num = re[index_replace_num - 1]
1819
re.insert(index_replace_num, '..')
1920
re.remove(re[index_replace_num - 1])
@@ -23,8 +24,9 @@ def type_brain_progress():
2324

2425

2526
def main():
26-
brain_games.sample.samples(CON_ANSWER, type_brain_progress(),
27-
type_brain_progress(), type_brain_progress())
27+
samples(CON_ANSWER, type_brain_progress(gen_rand_num()),
28+
type_brain_progress(gen_rand_num()),
29+
type_brain_progress(gen_rand_num()))
2830

2931

3032
if __name__ == '__main__':

brain_games/sample.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import prompt
2+
import random
3+
4+
25
NUMBERS_OF_ATTEMPTS = 3
36

47

8+
def gen_rand_num():
9+
frs_num = random.randint(1, 25)
10+
sec_num = random.randint(1, 25)
11+
arithmetic_operation = random.choice(['+', '-', '*'])
12+
return frs_num, sec_num, arithmetic_operation
13+
14+
515
def samples(condition_answer, answ_and_qest, answ_and_qest2, answ_and_qest3):
616
print('Welcome to the Brain Games!')
717
name = prompt.string('May I have your name? ')

0 commit comments

Comments
 (0)