Skip to content

Commit

Permalink
step 8: add brain-progression game
Browse files Browse the repository at this point in the history
  • Loading branch information
alinali87 committed Jul 2, 2024
1 parent aec4619 commit 9568358
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ brain-calc:
brain-gcd:
poetry run brain-gcd

brain-progression:
poetry run brain-progression

build:
poetry build

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@


#### Brain GCD Game
[![GCD Game](https://asciinema.org/a/IPYSjBiw3zFSf9BOp4qr0P4dM.svg)](https://asciinema.org/a/IPYSjBiw3zFSf9BOp4qr0P4dM)
[![GCD Game](https://asciinema.org/a/IPYSjBiw3zFSf9BOp4qr0P4dM.svg)](https://asciinema.org/a/IPYSjBiw3zFSf9BOp4qr0P4dM)


#### Brain Progression Game
[![Progression Game](https://asciinema.org/a/J4s6TNNnGl5zZfxwvF2PcnGzI.svg)](https://asciinema.org/a/J4s6TNNnGl5zZfxwvF2PcnGzI)
2 changes: 1 addition & 1 deletion brain_games/scripts/brain_gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from math import gcd
from brain_games.cli import welcome_user
from brain_games.utils import congrat_user, op_to_string
from brain_games.utils import congrat_user


def calc_game(name):
Expand Down
44 changes: 44 additions & 0 deletions brain_games/scripts/brain_progression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import prompt
import random
from math import gcd
from brain_games.cli import welcome_user
from brain_games.utils import congrat_user


def calc_game(name):
print('What number is missing in the progression?')
correct = 0
while True:
n = random.randint(6, 12)
start = random.randint(1, 10)
step = random.randint(1, 7)
nums = list(range(start, start + n * step + 1, step))
skip = random.choice(range(n))
correct_answer = nums[skip]
nums[skip] = ".."
print(f"Question: {' '.join(map(str, nums))}")
try:
a_str = prompt.string("Your answer: ")
a = int(a_str)
except ValueError as e:
print(f"Got ValueError: {e}")
a = a_str
if a == correct_answer:
correct += 1
print("Correct!")
else:
print(f"'{a}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
print(f"Let's try again, {name}!")
correct = 0
if correct == 3:
return True


def main():
name = welcome_user()
if calc_game(name):
congrat_user(name)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ brain-games = "brain_games.scripts.brain_games:main"
brain-even = "brain_games.scripts.brain_even:main"
brain-calc = "brain_games.scripts.brain_calc:main"
brain-gcd = "brain_games.scripts.brain_gcd:main"
brain-progression = "brain_games.scripts.brain_progression:main"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 9568358

Please sign in to comment.