Skip to content

Commit 2b2fefa

Browse files
committed
minor update code
1 parent 076d8f3 commit 2b2fefa

File tree

8 files changed

+21
-20
lines changed

8 files changed

+21
-20
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
__pycache__/
22
.venv/
33
.vscode/
4-
dist/
5-
.ruff_cache/
4+
dist/

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Brain Games
22
### About the project
33
This is a brain training game project. It consists of five games: "Calculator," "Parity Check," "Greatest Common Divisor (GCD)," "Arithmetic Progression," and "Is a Number Prime?" The project was created by Heklest student Andrey Vedenkin.
4+
### Game Rules
5+
You need to win three times in a row. If you answer incorrectly, the game ends.
46
### Hexlet tests and linter status:
57
[![Actions Status](https://github.com/Cheshire-12/python-project-49/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/Cheshire-12/python-project-49/actions)
68
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Cheshire-12_python-project-49&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Cheshire-12_python-project-49)

brain_games/engine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ def game_engine(game_description, question_generator):
88
score = 0
99
rounds = 3
1010
while score < rounds:
11-
question, correct_answer = question_generator()
11+
question, correct = question_generator()
1212
print(f"Question: {question}")
13-
user_answer = input("Your answer: ").strip()
14-
if user_answer == str(correct_answer):
13+
ans = input("Your answer: ").strip()
14+
if ans == str(ans):
1515
score += 1
1616
print("Correct!")
1717
else:
1818
score = 0
19-
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
19+
print(f"'{ans}' is wrong answer. Correct answer was '{correct}'.")
2020
print(f"Let's try again, {name}!")
2121
return
2222
print(f"Congratulations, {name}!")

brain_games/games/brain_calc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
DESCRIPTION = 'What is the result of the expression?'
66

77

8-
# Question and correct answer generator for Calc game.
8+
# Question and correct answer generator for Calculator game.
99
def generate_question():
1010
operations = {'+': operator.add,
1111
'-': operator.sub,
1212
'*': operator.mul
1313
}
14-
op_symbol = random.choice(list(operations.keys())) #NOSONAR
15-
num1 = random.randint(1, 25) #NOSONAR
16-
num2 = random.randint(1, 25) #NOSONAR
14+
op_symbol = random.choice(list(operations.keys())) # NOSONAR
15+
num1 = random.randint(1, 25) # NOSONAR
16+
num2 = random.randint(1, 25) # NOSONAR
1717
operator_func = operations[op_symbol]
1818
question = f"{num1} {op_symbol} {num2}"
1919
correct_answer = operator_func(num1, num2)

brain_games/games/brain_even.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
DESCRIPTION = 'Answer "yes" if the number is even, otherwise answer "no".'
44

55

6-
# Question and correct answer generator for Even game.
6+
# Question and correct answer generator for Parity Check game.
77
def generate_question():
8-
number = random.randint(1, 100) #NOSONAR
8+
number = random.randint(1, 100) # NOSONAR
99
question = str(number)
1010
correct_answer = 'yes' if number % 2 == 0 else 'no'
1111
return question, correct_answer

brain_games/games/brain_gcd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
# Question and correct answer generator for GCD game.
99
def generate_question():
10-
num1 = random.randint(1, 100) #NOSONAR
11-
num2 = random.randint(1, 100) #NOSONAR
10+
num1 = random.randint(1, 100) # NOSONAR
11+
num2 = random.randint(1, 100) # NOSONAR
1212
question = f"{num1} {num2}"
1313
correct_answer = math.gcd(num1, num2)
1414
return question, correct_answer

brain_games/games/brain_prime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def is_prime_number(n):
1717

1818
# Question and correct answer generator for Prime game.
1919
def generate_question():
20-
num = random.randint(1, 100) #NOSONAR
20+
num = random.randint(1, 100) # NOSONAR
2121
question = str(num)
2222
correct_answer = 'yes' if is_prime_number(num) else 'no'
2323
return question, correct_answer

brain_games/games/brain_progression.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
DESCRIPTION = "What number is missing in the progression?"
44

55

6-
# Question and correct answer generator for Brain Progression game.
6+
# Question and correct answer generator for Progression game.
77
def question_generator():
8-
progression_length = random.randint(5, 10) #NOSONAR
9-
start = random.randint(1, 20) #NOSONAR
10-
step = random.randint(1, 5) #NOSONAR
11-
hidden_index = random.randint(1, progression_length - 2) #NOSONAR
8+
progression_length = random.randint(5, 10) # NOSONAR
9+
start = random.randint(1, 20) # NOSONAR
10+
step = random.randint(1, 5) # NOSONAR
11+
hidden_index = random.randint(1, progression_length - 2) # NOSONAR
1212
progression = [str(start + i * step) for i in range(progression_length)]
1313
correct_answer = progression[hidden_index]
1414
progression[hidden_index] = '..'

0 commit comments

Comments
 (0)