Skip to content

Commit c095d55

Browse files
committed
Add brain-calc
1 parent c355783 commit c095d55

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
[![Maintainability](https://api.codeclimate.com/v1/badges/83457b9fd7b67208524c/maintainability)](https://codeclimate.com/github/BiscayN/python-project-49/maintainability)
77

88
### Brain-Even Test:
9-
[![asciicast](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc.svg)](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc)
9+
[![asciicast](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc.svg)](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc)
10+
11+
### Brain-Calc Test:
12+
[![asciicast](https://asciinema.org/a/mkMowswaIrjQpgW8QyvtBGrHi.svg)](https://asciinema.org/a/mkMowswaIrjQpgW8QyvtBGrHi)

brain_games/scripts/brain_calc.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from random import randint
2+
from random import choice
3+
from sys import exit
4+
from prompt import string
5+
6+
START_QUESTION = 'What is the result of the expression?'
7+
8+
9+
def get_values():
10+
num1, num2 = randint(1, 50), randint(1, 50)
11+
operator = choice(['+', '-', '*'])
12+
return num1, num2, operator
13+
14+
15+
def main():
16+
print('Welcome to the Brain Games!')
17+
name = string('May I have your name? ')
18+
print(f'Hello, {name}!')
19+
print(START_QUESTION)
20+
counter = 0
21+
while counter < 3:
22+
num1, num2, operator = get_values()
23+
question = f'{max(num1, num2)} {operator} {min(num1, num2)}'
24+
print(f'Question: {max(num1, num2)} {operator} {min(num1, num2)}')
25+
user_answer = string('Your answer: ')
26+
if str(eval(question)) == str(user_answer):
27+
print('Correct!')
28+
else:
29+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{eval(question)}'")
30+
print(f"Let's try again, {name}!")
31+
exit(0)
32+
counter += 1
33+
print(f'Congratulations, {name}!')
34+
exit(0)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ prompt = "^0.4.1"
1515
[tool.poetry.scripts]
1616
brain-games = "brain_games.scripts.brain_games:main"
1717
brain-even = "brain_games.scripts.brain_even:main"
18+
brain-calc = "brain_games.scripts.brain_calc:main"
1819

1920
[tool.poetry.group.dev.dependencies]
2021
flake8 = "^7.1.1"

0 commit comments

Comments
 (0)