Skip to content

Commit 38aed48

Browse files
committed
check 3
1 parent c4cf533 commit 38aed48

24 files changed

+132
-163
lines changed

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1+
### Brain-games
12
The game "Brain-games" includes 5 games.
23
To win each game, you need to give 3 correct answers.
34

4-
brain-even:
5+
1. brain-even:
56
You need to answer "yes" if given number is even, otherwise answer "no".
67

7-
brain-calc:
8+
2. brain-calc:
89
You need to write down thr calculation resuits.
910

10-
brain-gcd:
11+
3. brain-gcd:
1112
Find the greatest common divisor of given numbers.
1213

13-
brain-progression:
14+
4. brain-progression:
1415
You need to write down which number is missing in the progression.
1516

16-
brain-prime:
17+
5. brain-prime:
1718
You need to answer "yes" if given number is prime. Otherwise answer "no".
1819

1920
### Commands for calling games:
20-
brain-even
21-
brain-calc
22-
brain-gcd
23-
brain-progression
24-
brain-prime
21+
22+
* brain-even
23+
* brain-calc
24+
* brain-gcd
25+
* brain-progression
26+
* brain-prime
2527

2628
### Hexlet tests and linter status:
2729
[![Actions Status](https://github.com/s-gala/python-project-49/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/s-gala/python-project-49/actions)
@@ -30,31 +32,32 @@ brain-prime
3032
[![Maintainability](https://api.codeclimate.com/v1/badges/487e17fe16141caa4b2a/maintainability)](https://codeclimate.com/github/s-gala/python-project-49/maintainability)
3133

3234
### This project use:
33-
Python >= 3.10
34-
prompt >= 0.4.1
35+
* Python >= 3.10
36+
* prompt >= 0.4.1
3537

3638
### Install
3739

38-
git clone https://github.com/s-gala/python-project-49.git
39-
cd python-project-49
40-
make package-install
40+
* git clone https://github.com/s-gala/python-project-49.git
41+
* cd python-project-49
42+
* make package-install
4143

4244
### Removal
43-
cd pyton-project-49
44-
cd ../
45-
rm -rf python-project-49
45+
46+
* cd pyton-project-49
47+
* cd ../
48+
* rm -rf python-project-49
4649

4750
### Asciinema even
48-
[![Demo]( https://asciinema.org/a/wRnu8Sf53kCCvUfgqQixs0EPh )
51+
[![asciicast]( https://asciinema.org/a/wRnu8Sf53kCCvUfgqQixs0EPh )
4952

5053
### Asciinema calc
51-
[![Demo]( https://asciinema.org/a/S9Bly86EkmrpnTJhsAJU8pQDl )
54+
[![asciicast]( https://asciinema.org/a/S9Bly86EkmrpnTJhsAJU8pQDl )
5255

5356
### Asciinema gcd
54-
[![Demo]( https://asciinema.org/a/L5FDJeBgVySllsh5oELOwTtKa )
57+
[![asciicast]( https://asciinema.org/a/L5FDJeBgVySllsh5oELOwTtKa )
5558

5659
### Asciinema progression
57-
[![Demo]( https://asciinema.org/a/geOtpvl2IneSE65iIyp3BSoGY )
60+
[![asciicast]( https://asciinema.org/a/geOtpvl2IneSE65iIyp3BSoGY )
5861

5962
### Asciinema prime
60-
[![Demo]( https://asciinema.org/a/j2PgQoMiKCmVM1duYVp8pnN3i )
63+
[![asciicast]( https://asciinema.org/a/j2PgQoMiKCmVM1duYVp8pnN3i )

brain_games/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33

44
def welcome_user():
5-
print("Welcome to the Brain Games!")
6-
name = prompt.string('May I have your name? ')
5+
name = prompt.string('Welcome to the Brain Games!\nMay I have your name? ')
76
print(f'Hello, {name}!')
7+

brain_games/engine.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import prompt
2+
3+
4+
def game_engine(game):
5+
6+
name = prompt.string('Welcome to the Brain Games!\nMay I have your name? ')
7+
print(f'Hello, {name}!')
8+
print(game.INSTRUCTION)
9+
for _ in range(3):
10+
random_question, right_answer = game.get_question_answer()
11+
print(f"Question: {random_question}")
12+
answer = prompt.string('Your answer: ')
13+
if right_answer == answer:
14+
print('Correct!')
15+
else:
16+
print(f"'{answer}' is wrong answer;(. ", end='')
17+
print(f"Correct answer was '{right_answer}'.")
18+
print(f"Let's try again, {name}!")
19+
return
20+
return print(f"Congratulations, {name}!")

brain_games/games/calc.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import operator
2-
import random
1+
from brain_games import utils
2+
from brain_games.games import consts
33

4-
INSTRUCTION = "What is result of the expression?"
4+
INSTRUCTION = consts.INSTRUCTION_CALC
55

66

7-
def question_answer_calc():
8-
from brain_games.games import random_number
9-
x = random_number.get_random_number(1, 100)
10-
y = random_number.get_random_number(1, 100)
11-
math_symbol = {'+': operator.add,
12-
'-': operator.sub,
13-
'*': operator.mul}
14-
op = random.choice(list(math_symbol.keys()))
15-
random_question = f'{x}{op}{y}'
16-
right_answer = str(math_symbol.get(op)(x, y))
7+
def get_question_answer():
8+
x, y = utils.get_random_number(1, 100), utils.get_random_number(1, 100)
9+
sign, operator_metod = utils.get_random_operator()
10+
random_question = f'{x}{sign}{y}'
11+
right_answer = str(operator_metod(x, y))
1712
return random_question, right_answer

brain_games/games/consts.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSTRUCTION_CALC = "What is result of the expression?"
2+
3+
INSTRUCTION_EVEN = 'Answer "yes" if the number is even, otherwise answer "no".'
4+
5+
INSTRUCTION_GCD = "Find the greatest common divisor of given numbers."
6+
7+
INSTRUCTION_PRIME = \
8+
'Answer "yes" if given number is prime. Otherwise answer "no".'
9+
10+
INSTRUCTION_PROGRESSION = "What number is missing in the progression?"

brain_games/games/engine.py

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

brain_games/games/even.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
INSTRUCTION = 'Answer "yes" if the number is even, otherwise answer "no".'
1+
from brain_games.games import consts
22

3+
INSTRUCTION = consts.INSTRUCTION_EVEN
34

4-
def question_answer_even():
5-
from brain_games.games import random_number
6-
random_question = random_number.get_random_number(1, 100)
7-
right_answer = ''
8-
if random_question % 2 == 0:
9-
right_answer = 'yes'
10-
else:
11-
right_answer = 'no'
5+
6+
def get_question_answer():
7+
from brain_games import utils
8+
random_question = utils.get_random_number(1, 100)
9+
right_answer = 'yes' if random_question % 2 == 0 else 'no'
1210
return random_question, right_answer

brain_games/games/gcd.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import math
22

3-
INSTRUCTION = "Find the greatest common divisor of given numbers."
3+
from brain_games.games import consts
44

5+
INSTRUCTION = consts.INSTRUCTION_GCD
56

6-
def question_answer_gcd():
7-
from brain_games.games import random_number
8-
x = random_number.get_random_number(1, 100)
9-
y = random_number.get_random_number(1, 100)
7+
8+
def get_question_answer():
9+
from brain_games import utils
10+
x = utils.get_random_number(1, 100)
11+
y = utils.get_random_number(1, 100)
1012
random_question = f'{x} {y}'
1113
right_answer = str(math.gcd(x, y))
1214
return random_question, right_answer

brain_games/games/prime.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
INSTRUCTION = 'Answer "yes" if given number is prime. Otherwise answer "no".'
1+
from brain_games.games import consts
22

3+
INSTRUCTION = consts.INSTRUCTION_PRIME
34

4-
def question_answer_prime():
5-
from brain_games.games import random_number
6-
random_question = random_number.get_random_number(1, 100)
5+
6+
def get_question_answer():
7+
from brain_games import utils
8+
random_question = utils.get_random_number(1, 100)
79
k = 0
810
for i in range(2, random_question // 2 + 1):
911
if (random_question % i == 0):
1012
k = k + 1
11-
if (k <= 0):
12-
right_answer = 'yes'
13-
else:
14-
right_answer = 'no'
13+
right_answer = 'yes' if (k <= 0) else 'no'
1514
return random_question, right_answer

0 commit comments

Comments
 (0)