Skip to content

Commit f936430

Browse files
committed
created brain-calc
1 parent ef289fd commit f936430

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
[![Maintainability](https://api.codeclimate.com/v1/badges/e9fd145072b912372b3e/maintainability)](https://codeclimate.com/github/P-Solod/python-project-50/maintainability)
55

66
[![asciicast](https://asciinema.org/a/klBAIJgaHlmUxnNpXJSDnMRZn.svg)](https://asciinema.org/a/klBAIJgaHlmUxnNpXJSDnMRZn)
7+
8+
[![asciicast](https://asciinema.org/a/bbazsgsgH7VqjSxyksMPzc9bj.svg)](https://asciinema.org/a/bbazsgsgH7VqjSxyksMPzc9bj)

brain_games/scripts/brain_calc.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import random
2+
3+
import prompt
4+
5+
def main():
6+
print('Welcome to the Brain Games!')
7+
name = prompt.string('May I have your name? ')
8+
print(f'Hello, {name}!')
9+
print('What is the result of the expression?')
10+
11+
count = 0
12+
13+
while count < 3:
14+
number_1 = random.randint(1, 100)
15+
number_2 = random.randint(1, 100)
16+
symbols = ['+', '-', '*']
17+
symbol = random.choice(symbols)
18+
19+
if symbol == '+':
20+
result = number_1 + number_2
21+
elif symbol == '-':
22+
result = number_1 - number_2
23+
else:
24+
result = number_1 * number_2
25+
26+
print(f'Question: {number_1} {symbol} {number_2}')
27+
answer = prompt.integer('Your answer: ')
28+
29+
if answer == result:
30+
print('Correct!')
31+
count += 1
32+
else:
33+
print(f"'{answer}' is wrong answer ;(. "
34+
f"Correct answer was '{result}'.")
35+
print(f"Let's try again, {name}")
36+
break
37+
38+
else:
39+
print(f'Congratulations, {name}!')
40+
41+
if __name__ == '__main__':
42+
main()

demo_1.cast

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{"version": 2, "width": 120, "height": 30, "timestamp": 1739294411, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.030713, "o", "\u001b[?2004h\u001b]0;mitsyaki@DESKTOP-SKJO0UG: ~/python-project-49\u0007\u001b[01;32mmitsyaki@DESKTOP-SKJO0UG\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
3+
[2.501276, "o", "b"]
4+
[2.693733, "o", "r"]
5+
[2.914274, "o", "a"]
6+
[3.086661, "o", "i"]
7+
[3.283849, "o", "n"]
8+
[3.784943, "o", "-"]
9+
[3.984205, "o", "c"]
10+
[4.150943, "o", "a"]
11+
[4.340514, "o", "l"]
12+
[4.599236, "o", "c"]
13+
[5.704936, "o", "\r\n\u001b[?2004l\r"]
14+
[5.733579, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
15+
[6.933426, "o", "P"]
16+
[7.41237, "o", "a"]
17+
[8.134672, "o", "v"]
18+
[8.37253, "o", "e"]
19+
[8.645882, "o", "l"]
20+
[9.469976, "o", "\r\n"]
21+
[9.470351, "o", "Hello, Pavel!\r\nWhat is the result of the expression?\r\nQuestion: 57 + 57\r\nYour answer: "]
22+
[16.166739, "o", "1"]
23+
[16.330195, "o", "1"]
24+
[16.505276, "o", "4"]
25+
[17.195659, "o", "\r\n"]
26+
[17.195991, "o", "Correct!\r\nQuestion: 13 - 64\r\nYour answer: "]
27+
[22.12706, "o", "-"]
28+
[23.401511, "o", "5"]
29+
[23.606901, "o", "1"]
30+
[24.478804, "o", "\r\n"]
31+
[24.479114, "o", "Correct!\r\nQuestion: 59 + 21\r\nYour answer: "]
32+
[36.04237, "o", "8"]
33+
[36.323561, "o", "0"]
34+
[36.616469, "o", "\r\n"]
35+
[36.616748, "o", "Correct!\r\nCongratulations, Pavel!\r\n"]
36+
[36.62258, "o", "\u001b[?2004h\u001b]0;mitsyaki@DESKTOP-SKJO0UG: ~/python-project-49\u0007\u001b[01;32mmitsyaki@DESKTOP-SKJO0UG\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
37+
[39.453628, "o", "brain-calc"]
38+
[40.175762, "o", "\r\n\u001b[?2004l\r"]
39+
[40.206933, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
40+
[41.382854, "o", "P"]
41+
[41.606433, "o", "a"]
42+
[41.885769, "o", "v"]
43+
[42.058279, "o", "e"]
44+
[42.270123, "o", "l"]
45+
[42.735132, "o", "\r\n"]
46+
[42.735249, "o", "Hello, Pavel!\r\nWhat is the result of the expression?\r\nQuestion: 48 + 91\r\nYour answer: "]
47+
[44.048433, "o", "3"]
48+
[44.568683, "o", "\r\n"]
49+
[44.569008, "o", "'3' is wrong answer ;(. Correct answer was '139'.\r\nLet's try again, Pavel\r\n"]
50+
[44.574683, "o", "\u001b[?2004h\u001b]0;mitsyaki@DESKTOP-SKJO0UG: ~/python-project-49\u0007\u001b[01;32mmitsyaki@DESKTOP-SKJO0UG\u001b[00m:\u001b[01;34m~/python-project-49\u001b[00m$ "]
51+
[46.235207, "o", "e"]
52+
[46.326944, "o", "e"]
53+
[46.672253, "o", "x"]
54+
[46.974101, "o", "i"]
55+
[47.228515, "o", "t"]
56+
[47.943971, "o", "\b\u001b[K"]
57+
[48.095627, "o", "\b\u001b[K"]
58+
[48.248619, "o", "\b\u001b[K"]
59+
[48.392309, "o", "\b\u001b[K"]
60+
[48.720815, "o", "x"]
61+
[49.070673, "o", "i"]
62+
[49.284531, "o", "t"]
63+
[49.805781, "o", "\r\n\u001b[?2004l\rexit\r\n"]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ dev = [
2323
[project.scripts]
2424
brain-games = "brain_games.scripts.brain_games:main"
2525
brain-even = "brain_games.scripts.brain_even:main"
26+
brain-calc = "brain_games.scripts.brain_calc:main"

0 commit comments

Comments
 (0)