Skip to content

Commit 6152bb9

Browse files
committed
many updates.+games,edit scripts,+ все що написав наставник
1 parent 045c3bc commit 6152bb9

File tree

16 files changed

+146
-111
lines changed

16 files changed

+146
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.venv
2+
__pycache__/
-154 Bytes
Binary file not shown.

brain_games/game_logic.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
def start_game(description, question_func):
2-
3-
print("Welcome to the Brain Games!")
4-
name = input("May I have your name? ").strip()
5-
print(f"Hello, {name}!")
1+
def start_game(description, question_func, name):
62
print(description)
73

84
rounds_to_win = 3
@@ -20,4 +16,4 @@ def start_game(description, question_func):
2016

2117
print("Correct!")
2218

23-
print(f"Congratulations, {name}!")
19+
print(f"Congratulations, {name}!")

brain_games/games/calc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
3+
MIN_NUMBER = 1
4+
MAX_NUMBER = 100
5+
OPERATIONS = ["+", "-", "*"]
6+
7+
8+
def generate_calculation():
9+
num1 = random.randint(MIN_NUMBER, MAX_NUMBER)
10+
num2 = random.randint(MIN_NUMBER, MAX_NUMBER)
11+
operation = random.choice(OPERATIONS)
12+
question = f"{num1} {operation} {num2}"
13+
14+
if operation == "+":
15+
correct_answer = num1 + num2
16+
elif operation == "-":
17+
correct_answer = num1 - num2
18+
else:
19+
correct_answer = num1 * num2
20+
21+
return question, correct_answer

brain_games/games/even.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import random
2+
3+
MIN_NUMBER = 1
4+
MAX_NUMBER = 100
5+
ROUNDS_TO_WIN = 3
6+
7+
8+
def is_even(number):
9+
return number % 2 == 0
10+
11+
12+
def generate_question():
13+
number = random.randint(MIN_NUMBER, MAX_NUMBER)
14+
correct_answer = "yes" if is_even(number) else "no"
15+
question = str(number)
16+
return question, correct_answer

brain_games/games/gcd.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import random
2+
from math import gcd
3+
4+
MIN_NUMBER = 1
5+
MAX_NUMBER = 100
6+
ROUNDS_TO_WIN = 3
7+
8+
9+
def generate_question():
10+
number1 = random.randint(MIN_NUMBER, MAX_NUMBER)
11+
number2 = random.randint(MIN_NUMBER, MAX_NUMBER)
12+
question = f"Question: {number1} {number2}"
13+
14+
correct_answer = gcd(number1, number2)
15+
return question, correct_answer

brain_games/games/prime.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import random
2+
3+
MIN_NUMBER = 1
4+
MAX_NUMBER = 100
5+
PRIME_MIN = 2
6+
7+
8+
def is_prime(number):
9+
if number < PRIME_MIN:
10+
return False
11+
for i in range(PRIME_MIN, int(number ** 0.5) + 1):
12+
if number % i == 0:
13+
return False
14+
return True
15+
16+
17+
def generate_question():
18+
number = random.randint(MIN_NUMBER, MAX_NUMBER)
19+
correct_answer = "yes" if is_prime(number) else "no"
20+
question = str(number)
21+
return question, correct_answer

brain_games/games/progression.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import random
2+
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+
10+
11+
def generate_progression():
12+
length = random.randint(MIN_LENGTH, MAX_LENGTH)
13+
start = random.randint(MIN_START, MAX_START)
14+
step = random.randint(MIN_STEP, MAX_STEP)
15+
16+
progression = [start + i * step for i in range(length)]
17+
hidden_index = random.randint(0, length - 1)
18+
correct_answer = progression[hidden_index]
19+
20+
progression[hidden_index] = ".."
21+
question = " ".join(map(str, progression))
22+
23+
return question, correct_answer
-162 Bytes
Binary file not shown.
-388 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)