|
1 | | -from random import randint |
2 | | -from random import choice |
3 | | -from sys import exit |
4 | | -from prompt import string |
| 1 | +#!/usr/bin/env python3 |
| 2 | +from brain_games.games import calc |
| 3 | +from brain_games.src import solution |
5 | 4 |
|
6 | | -START_QUESTION = 'What is the result of the expression?' |
7 | 5 |
|
8 | | - |
9 | | -def get_values(): |
10 | | - num1, num2 = randint(1, 50), randint(1, 50) |
11 | | - operator = choice(['+', '-', '*']) |
12 | | - return num1, num2, operator |
| 6 | +def main(): |
| 7 | + solution(calc) |
13 | 8 |
|
14 | 9 |
|
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 " |
30 | | - f";(. Correct answer was '{eval(question)}'") |
31 | | - print(f"Let's try again, {name}!") |
32 | | - exit(0) |
33 | | - counter += 1 |
34 | | - print(f'Congratulations, {name}!') |
35 | | - exit(0) |
| 10 | +if __name__ == '__main__': |
| 11 | + main() |
0 commit comments