Skip to content

Commit 8048365

Browse files
Initial project
1 parent 884a73a commit 8048365

6 files changed

Lines changed: 337 additions & 123 deletions

File tree

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ brain_calc:
1212
brain_gcd:
1313
uv run brain_gcd
1414

15+
brain_progression:
16+
uv run brain_progression
17+
18+
brain_prime:
19+
uv run brain_prime
20+
1521
build:
1622
uv build
1723

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@
2020
**Задача:** Найти НОД двух чисел
2121

2222
**Запуск:** `python3 -m brain_games.scripts.brain_gcd`
23-
[![brain-gcd demo]](https://asciinema.org/a/RYSXYk7yH0ogayCc)
23+
[![brain-gcd demo]](https://asciinema.org/a/RYSXYk7yH0ogayCc)
24+
## brain-progression
25+
26+
**Задача:** Найти пропущенное число в арифметической прогрессии
27+
28+
**Запуск:** `python3 -m brain_games.scripts.brain_progression`
29+
[![brain-progression demo]](https://asciinema.org/a/92RAZC1O8MenwsfU)

brain_games/scripts/brain_prime.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import random
2+
from brain_games.cli import welcome_user
3+
4+
DESCRIPTION = "Answer 'yes' if given number is prime. Otherwise answer 'no'."
5+
6+
def is_prime(n):
7+
if n < 2:
8+
return False
9+
for i in range(2, int(n**0.5)+ 1):
10+
if n % i == 0:
11+
return False
12+
return True
13+
14+
def get_prime_question():
15+
number = random.randint(2, 100)
16+
correct_answer = 'yes' if is_prime(number) else 'no'
17+
question = str(number)
18+
return correct_answer, question
19+
20+
def main():
21+
name = welcome_user()
22+
print(DESCRIPTION)
23+
24+
correct_answers = 0
25+
while correct_answers < 3:
26+
correct_answer, question = get_prime_question()
27+
print(f"Question: {question}")
28+
user_answer = input("You answer: ")
29+
30+
if user_answer.lower() == correct_answer:
31+
print("Correct")
32+
correct_answers += 1
33+
else:
34+
print(f"'{user_answer}' is wrong answer ;(. ")
35+
print(f"Correct answer was '{correct_answer}'.")
36+
print(f"Let's try again, {name}!")
37+
break
38+
if correct_answers == 3:
39+
print(f"Congratulations, {name}!")
40+
41+
if __name__ == '__main__':
42+
main()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import random
2+
from brain_games.cli import welcome_user
3+
4+
DESCRIPTION = "What number is missing in the progression?"
5+
6+
def generate_progression():
7+
length = random.randint(5,10)
8+
start = random.randint(1,50)
9+
step = random.randint(2,10)
10+
11+
missing_idx = random.randint(0, length -1)
12+
13+
progression = []
14+
for i in range(length):
15+
number = start + i * step
16+
progression.append(str(number))
17+
18+
correct_answer = progression[missing_idx]
19+
progression[missing_idx] = ".."
20+
21+
question = " ".join(progression)
22+
return correct_answer,question
23+
24+
def main():
25+
name = welcome_user()
26+
print(DESCRIPTION)
27+
28+
correct_answers = 0
29+
30+
while correct_answers < 3:
31+
correct_answer, question = generate_progression()
32+
print(f"Question: {question}")
33+
user_answer = input("You answer: ")
34+
35+
if user_answer == correct_answer:
36+
print("Correct!")
37+
correct_answers += 1
38+
else:
39+
print(f"'{user_answer}' is wrong answer ;(. ")
40+
print(f"Correct answer was '{correct_answer}'.")
41+
print(f"Let's try again, {name}!")
42+
break
43+
44+
if correct_answers == 3:
45+
print(f"Congratulations, {name}!")
46+
47+
if __name__ == '__main__':
48+
main()

0 commit comments

Comments
 (0)