Skip to content

Commit 2cc060e

Browse files
committed
new game brain-prime
1 parent 4d51494 commit 2cc060e

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ brain-gcd:
1717
brain-progression:
1818
poetry run brain-progression
1919

20+
brain-prime:
21+
poetry run brain-prime
22+
2023
build:
2124
poetry build
2225

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
[![asciinema](https://asciinema.org/a/PSMfRjtLIYa1SfJU35MwgvQqp.svg)](https://asciinema.org/a/PSMfRjtLIYa1SfJU35MwgvQqp)
1212

13+
[![asciinema](https://asciinema.org/a/u65aOmJ8p8h8jzNnKyOHT7yD4.svg)](https://asciinema.org/a/u65aOmJ8p8h8jzNnKyOHT7yD4)
14+
1315
<a href="https://codeclimate.com/github/Nurzhan2023/python-project-49/maintainability"><img src="https://api.codeclimate.com/v1/badges/364adb79c130f5d257e8/maintainability" /></a>
1416

1.13 KB
Binary file not shown.

brain_games/scripts/brain_prime.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# brain_games/scripts/brain_prime.py
2+
3+
4+
import random
5+
import prompt
6+
7+
8+
9+
def main():
10+
ROUNDS_COUNT = 1
11+
12+
13+
print("Welcome to the Brain Games!")
14+
name = prompt.string("May I have your name?")
15+
print(f"Hello, {name}!")
16+
print('Answer "Yes" if given number is prime. Otherwise answer "no".')
17+
18+
19+
for i in range(ROUNDS_COUNT):
20+
question, correct_answer = prime()
21+
print(f"Question: {question}")
22+
answer = prompt.string("Your answer: ").strip().lower()
23+
24+
if answer != correct_answer:
25+
print(f"'{answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
26+
print (f"Let's try again, {name}!")
27+
return
28+
29+
else:
30+
print("Correct!")
31+
32+
33+
34+
def prime():
35+
number = random.randint(1, 100)
36+
question = str(number)
37+
38+
39+
if number <= 1:
40+
correct_answer = "no"
41+
else:
42+
for i in range(2, int(number ** 0.5) + 1):
43+
if number % i == 0:
44+
correct_answer = "no"
45+
break
46+
else:
47+
correct_answer = "yes"
48+
49+
return question, correct_answer
50+
51+
52+
53+
54+
if __name__ == "__main__":
55+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ brain-even = "brain_games.scripts.brain_even:main"
1818
brain-calc = "brain_games.scripts.brain_calc:main"
1919
brain-gcd = "brain_games.scripts.brain_gcd:main"
2020
brain-progression = "brain_games.scripts.brain_progression:main"
21+
brain-prime = "brain_games.scripts.brain_prime:main"
2122
[tool.poetry.group.dev.dependencies]
2223
flake8 = "^7.1.1"
2324

0 commit comments

Comments
 (0)