Skip to content

Commit

Permalink
part9
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Antipova committed Dec 15, 2024
1 parent ac9d06d commit ff8db10
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
[![asciinema](https://asciinema.org/a/9fmaWyvkpTITNMe9PyHwkvj52)](https://asciinema.org/a/9fmaWyvkpTITNMe9PyHwkvj52)

[![asciinema](https://asciinema.org/a/anfIkHRxCU4Ies9YNlgB5hpPn)](https://asciinema.org/a/anfIkHRxCU4Ies9YNlgB5hpPn)

[![asciinema](https://asciinema.org/a/52SPBQWiZiTeOCVKaDfOyPwrK)](https://asciinema.org/a/52SPBQWiZiTeOCVKaDfOyPwrK)
123 changes: 123 additions & 0 deletions brain-prime-demo.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{"version": 2, "width": 120, "height": 30, "timestamp": 1734263032, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
[0.014381, "o", "\u001b[?2004h\u001b]0;beril@HOME-PC: ~/python-project-49\u0007\u001b[01;32mberil@HOME-PC\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
[2.556851, "o", "b"]
[2.716118, "o", "r"]
[3.040677, "o", "a"]
[3.221154, "o", "i"]
[3.463904, "o", "n"]
[3.993866, "o", "-"]
[4.603334, "o", "p"]
[4.725913, "o", "r"]
[4.923942, "o", "i"]
[5.487842, "o", "m"]
[5.57549, "o", "e"]
[5.986113, "o", "\r\n\u001b[?2004l\r"]
[6.00191, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
[7.058975, "o", "M"]
[7.256983, "o", "a"]
[7.536692, "o", "r"]
[7.784128, "o", "i"]
[7.92437, "o", "a"]
[8.640959, "o", "\r\nHello, Maria!\r\nAnswer \"yes\" if given number is prime. Otherwise answer \"no\".\r\n"]
[8.641156, "o", "Question: 9\r\nYour answer: "]
[10.620981, "o", "n"]
[10.936519, "o", "o"]
[11.669547, "o", "\r\n"]
[11.66975, "o", "Correct!\r\nQuestion: 54\r\nYour answer: "]
[15.176676, "o", "y"]
[17.111188, "o", "e"]
[17.428743, "o", "s"]
[18.078821, "o", "\r\n"]
[18.079002, "o", "'yes' is wrong answer ;(. Correct answer was 'no'.\r\nLet's try again, Maria!\r\n"]
[18.083576, "o", "\u001b[?2004h\u001b]0;beril@HOME-PC: ~/python-project-49\u0007\u001b[01;32mberil@HOME-PC\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
[20.391274, "o", "b"]
[20.728028, "o", "r"]
[21.019583, "o", "a"]
[21.337356, "o", "i"]
[21.61345, "o", "n"]
[22.515976, "o", "-"]
[23.426064, "o", "p"]
[23.513835, "o", "r"]
[24.453334, "o", "i"]
[24.907389, "o", "m"]
[24.973963, "o", "e"]
[25.646745, "o", "\r\n\u001b[?2004l\r"]
[25.66259, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
[26.63261, "o", "M"]
[26.813597, "o", "a"]
[27.180737, "o", "r"]
[27.393137, "o", "i"]
[27.560831, "o", "a"]
[28.206311, "o", "\r\n"]
[28.206546, "o", "Hello, Maria!\r\nAnswer \"yes\" if given number is prime. Otherwise answer \"no\".\r\nQuestion: 35\r\nYour answer: "]
[30.209476, "o", "y"]
[30.530673, "o", "e"]
[30.625708, "o", "s"]
[31.381412, "o", "\r\n"]
[31.381664, "o", "'yes' is wrong answer ;(. Correct answer was 'no'.\r\nLet's try again, Maria!\r\n"]
[31.386041, "o", "\u001b[?2004h\u001b]0;beril@HOME-PC: ~/python-project-49\u0007\u001b[01;32mberil@HOME-PC\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
[35.863277, "o", "b"]
[35.879498, "o", "r"]
[36.246206, "o", "a"]
[36.460447, "o", "i"]
[36.728946, "o", "n"]
[37.336116, "o", "-"]
[37.887113, "o", "p"]
[38.255448, "o", "r"]
[38.450917, "o", "i"]
[38.687345, "o", "m"]
[38.826851, "o", "e"]
[39.206224, "o", "\r\n\u001b[?2004l\r"]
[39.222255, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
[40.228633, "o", "M"]
[40.424424, "o", "a"]
[40.717637, "o", "r"]
[40.966277, "o", "i"]
[41.123321, "o", "a"]
[41.74328, "o", "\r\n"]
[41.743532, "o", "Hello, Maria!\r\n"]
[41.743693, "o", "Answer \"yes\" if given number is prime. Otherwise answer \"no\".\r\nQuestion: 64\r\nYour answer: "]
[44.12924, "o", "n"]
[44.554963, "o", "o"]
[45.01404, "o", "\r\n"]
[45.014292, "o", "Correct!\r\nQuestion: 97\r\nYour answer: "]
[47.646746, "o", "n"]
[48.036428, "o", "o"]
[48.482157, "o", "\r\n"]
[48.482377, "o", "'no' is wrong answer ;(. Correct answer was 'yes'.\r\nLet's try again, Maria!\r\n"]
[48.487186, "o", "\u001b[?2004h\u001b]0;beril@HOME-PC: ~/python-project-49\u0007\u001b[01;32mberil@HOME-PC\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
[51.116452, "o", "b"]
[51.402986, "o", "r"]
[51.725402, "o", "a"]
[51.932128, "o", "i"]
[52.224015, "o", "n"]
[52.694785, "o", "-"]
[53.315393, "o", "p"]
[53.450396, "o", "r"]
[53.649673, "o", "i"]
[53.92549, "o", "m"]
[54.103494, "o", "e"]
[54.47432, "o", "\r\n\u001b[?2004l\r"]
[54.489937, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
[55.693897, "o", "M"]
[55.905075, "o", "a"]
[56.221992, "o", "r"]
[56.449773, "o", "i"]
[56.617667, "o", "a"]
[56.872211, "o", "\r\n"]
[56.872417, "o", "Hello, Maria!\r\nAnswer \"yes\" if given number is prime. Otherwise answer \"no\".\r\nQuestion: 62\r\nYour answer: "]
[59.007057, "o", "n"]
[59.593665, "o", "o"]
[60.223421, "o", "\r\nCorrect!\r\n"]
[60.223652, "o", "Question: 47\r\nYour answer: "]
[62.778693, "o", "y"]
[63.069851, "o", "e"]
[63.18256, "o", "s"]
[63.501663, "o", "\r\n"]
[63.501818, "o", "Correct!\r\nQuestion: 40\r\nYour answer: "]
[65.182115, "o", "n"]
[65.666088, "o", "o"]
[66.266424, "o", "\r\nCorrect!\r\n"]
[66.266657, "o", "Congratulations, Maria!\r\n"]
[66.270977, "o", "\u001b[?2004h\u001b]0;beril@HOME-PC: ~/python-project-49\u0007\u001b[01;32mberil@HOME-PC\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
[67.602637, "o", "\u001b[?2004l\r\r\nexit\r\n"]
35 changes: 35 additions & 0 deletions brain_games/scripts/brain_prime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import random
import sys


def is_prime(number):
if number < 2:
return False
for i in range(2, int(number ** 0.5) + 1):
if number % i == 0:
return False
return True


def run_game():
print("Welcome to the Brain Games!")
name = input("May I have your name? ")
print(f"Hello, {name}!")
print('Answer "yes" if given number is prime. Otherwise answer "no".')

for _ in range(3):
number = random.randint(1, 100)
correct_answer = "yes" if is_prime(number) else "no"
print(f"Question: {number}")
user_answer = input("Your answer: ")
if user_answer == correct_answer:
print("Correct!")
else:
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
print(f"Let's try again, {name}!")
return
print(f"Congratulations, {name}!")


if __name__ == "__main__":
sys.exit(run_game())
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ brain-even = "brain_games.scripts.brain_even:run_game"
brain-calc = "brain_games.scripts.brain_calc:run_game"
brain-gcd = "brain_games.scripts.brain_gcd:run_game"
brain-progression = "brain_games.scripts.brain_progression:run_game"
brain-prime = "brain_games.scripts.brain_prime:run_game"

0 comments on commit ff8db10

Please sign in to comment.