Skip to content

Commit 191afeb

Browse files
committed
added game: Brain-even
1 parent ae11ea1 commit 191afeb

File tree

7 files changed

+68
-3
lines changed

7 files changed

+68
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__pycache__/
2-
.venv/
2+
.venv/
3+
.vscode/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Cheshire-12_python-project-49&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Cheshire-12_python-project-49)
2121

22-
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Cheshire-12_python-project-49&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Cheshire-12_python-project-49)
22+
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Cheshire-12_python-project-49&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Cheshire-12_python-project-49)

brain_games/games/__init__.py

Whitespace-only changes.

brain_games/games/brain_even.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import random
2+
3+
4+
# Brain Even Game
5+
def is_even(number):
6+
# Check if a number is even.
7+
return number % 2 == 0
8+
9+
10+
def get_user_name():
11+
# Get the user's name.
12+
return input("May I have your name? ")
13+
14+
15+
def play_brain_even():
16+
score = 0
17+
rounds = 3
18+
# Play the Brain Even game.
19+
print("Welcome to the Brain Games!")
20+
name = get_user_name()
21+
print(f"Hello, {name}!")
22+
print("Answer 'yes' if the number is even, otherwise answer 'no'.")
23+
24+
# Game loop
25+
while score < rounds:
26+
# Generate a random number
27+
number = random.randint(1, 100)
28+
print(f"Question: {number}")
29+
30+
# Get user input
31+
user_answer = input("Your answer: ").strip().lower()
32+
33+
# Check if the answer is correct
34+
if (is_even(number) and user_answer == "yes") or (not is_even(number) and user_answer == "no"):
35+
score += 1
36+
print("Correct!")
37+
else:
38+
score = 0
39+
print("Wrong answer. Let's try again!")
40+
print(f"Congratulations, {name}!")

brain_games/scripts/brain_even.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from brain_games.games.brain_even import play_brain_even
2+
3+
4+
def main():
5+
play_brain_even()
6+
7+
8+
if __name__ == '__main__':
9+
main()

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ packages = ["brain_games"]
1717

1818
[dependency-groups]
1919
dev = [
20+
"asciinema>=2.4.0",
2021
"ruff>=0.14.2",
2122
]
2223

2324
[project.scripts]
2425
brain-games = "brain_games.scripts.brain_games:main"
26+
brain-even = "brain_games.scripts.brain_even:main"

uv.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)