File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
brain_games/scripts/games Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ brain-gcd:
1616brain-progression :
1717 uv run brain-progression
1818
19+ brain-prime :
20+ uv run brain-prime
21+
1922build :
2023 uv build
2124
Original file line number Diff line number Diff line change 2525### Asciinema: step 8: brain-progression
2626
2727[ ![ asciicast] ( https://asciinema.org/a/C6YfeEUsekaaOdIIdAwfl0vZi.svg )] ( https://asciinema.org/a/C6YfeEUsekaaOdIIdAwfl0vZi )
28+
29+ ### Asciinema: step 9: brain-prime
30+
31+ [ ![ asciicast] ( https://asciinema.org/a/5IFJqgQEw9TpbY3lFXAPhE8Go.svg )] ( https://asciinema.org/a/5IFJqgQEw9TpbY3lFXAPhE8Go )
Original file line number Diff line number Diff line change 1+ from random import randint
2+
3+ from brain_games .engine import engine
4+
5+ GAME_TASK = 'Answer "yes" if given number is prime. Otherwise answer "no".'
6+ MIN_NUMBER = 2
7+ MAX_NUMBER = 50
8+
9+
10+ def get_random_number ():
11+ return randint (MIN_NUMBER , MAX_NUMBER )
12+
13+
14+ def is_prime (num ):
15+ counter = 2
16+ while counter <= num / 2 :
17+ if num % counter == 0 :
18+ return False
19+ counter += 1
20+ return True
21+
22+
23+ def get_game_data ():
24+ game_question = get_random_number ()
25+ game_answer = 'yes' if is_prime (game_question ) else 'no'
26+ return [str (game_question ), game_answer ]
27+
28+
29+ def main ():
30+ engine (GAME_TASK , get_game_data )
31+
32+
33+ if __name__ == "__main__" :
34+ main ()
Original file line number Diff line number Diff line change @@ -26,3 +26,4 @@ brain-even = "brain_games.scripts.games.brain_even:main"
2626brain-calc = " brain_games.scripts.games.brain_calc:main"
2727brain-gcd = " brain_games.scripts.games.brain_gcd:main"
2828brain-progression = " brain_games.scripts.games.brain_progression:main"
29+ brain-prime = " brain_games.scripts.games.brain_prime:main"
You can’t perform that action at this time.
0 commit comments