File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -13,5 +13,8 @@ brain-games:
1313brain-even :
1414 uv run brain-even
1515
16+ brain-calc :
17+ uv run brain-calc
18+
1619lint :
1720 uv run ruff check brain_games
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import prompt
3+ import random
4+ def main ():
5+ print ('Welcome to the Brain Games!' )
6+ name = prompt .string ('May I have your name? ' )
7+ print (f'Hello, { name } ' )
8+ print ('What is the result of the expression?' )
9+ n = 0
10+ while n < 3 :
11+ num1 = random .randint (1 , 50 )
12+ num2 = random .randint (1 , 50 )
13+ operation = random .choice (['+' , '-' , '*' ])
14+ expression = f'{ num1 } { operation } { num2 } '
15+ result = eval (expression )
16+ print (f'Question: { expression } ' )
17+ answer = int (prompt .string ('Your answer: ' ))
18+ if result == answer :
19+ n += 1
20+ if n < 3 :
21+ print ('Correct!' )
22+ else :
23+ print (f'Congratulations, { name } !' )
24+ else :
25+ print (f"{ answer } is wrong answer ;(. Correct answer was { result } .\n Let's try again, { name } " )
26+ break
27+
28+ if __name__ == '__main__' :
29+ main ()
Original file line number Diff line number Diff line change 11[project ]
22name = " hexlet-code"
3- version = " 0.3.0 "
3+ version = " 0.3.1 "
44description = " Add your description here"
55readme = " README.md"
66requires-python = " >=3.10"
@@ -22,4 +22,5 @@ dev = [
2222
2323[project .scripts ]
2424brain-games = " brain_games.scripts.brain_games:main"
25- brain-even = " brain_games.scripts.brain_even:main"
25+ brain-even = " brain_games.scripts.brain_even:main"
26+ brain-calc = " brain_games.scripts.brain_calc:main"
You can’t perform that action at this time.
0 commit comments