|
| 1 | +import prompt |
| 2 | +import random |
| 3 | +# import brain_games.scripts.games.brain_calc |
| 4 | +# import brain_games.scripts.games.brain_even |
| 5 | +# import brain_games.scripts.games.brain_gcd |
| 6 | + |
| 7 | + |
| 8 | +NUMBERS_OF_ATTEMPTS = 3 |
| 9 | + |
| 10 | + |
| 11 | +def samples(type_game, condition_answer): |
| 12 | + print('Welcome to the Brain Games!') |
| 13 | + name = prompt.string('May I have your name? ') |
| 14 | + print(f'Hello, {name}!') |
| 15 | + number_of_successful_attempts = 0 |
| 16 | + print(condition_answer) |
| 17 | + for _ in range(NUMBERS_OF_ATTEMPTS): |
| 18 | + first_number = random.randint(1, 50) |
| 19 | + second_number = random.randint(1, 50) |
| 20 | + match type_game: |
| 21 | + case 'brain-even': |
| 22 | + import brain_games.scripts.games.brain_even |
| 23 | + correct_answer, question = ( |
| 24 | + brain_games.scripts.games. |
| 25 | + brain_even.type_brain_even(first_number)) |
| 26 | + case 'brain-calc': |
| 27 | + import brain_games.scripts.games.brain_calc |
| 28 | + first_number = random.randint(1, 25) |
| 29 | + second_number = random.randint(1, 25) |
| 30 | + arithmetic_operation = random.choice(['+', '-', '*']) |
| 31 | + correct_answer, question = ( |
| 32 | + brain_games.scripts.games. |
| 33 | + brain_calc.type_brain_calc(first_number, second_number, |
| 34 | + arithmetic_operation)) |
| 35 | + case 'brain-gcd': |
| 36 | + import brain_games.scripts.games.brain_gcd |
| 37 | + correct_answer, question = ( |
| 38 | + brain_games.scripts.games. |
| 39 | + brain_gcd.type_brain_gcd(first_number, second_number)) |
| 40 | + case 'brain-progression': |
| 41 | + import brain_games.scripts.games.brain_progression |
| 42 | + correct_answer, question = ( |
| 43 | + brain_games.scripts.games. |
| 44 | + brain_progression.type_brain_progression(first_number)) |
| 45 | + case 'brain-prime': |
| 46 | + import brain_games.scripts.games.brain_prime |
| 47 | + correct_answer, question = ( |
| 48 | + brain_games.scripts.games. |
| 49 | + brain_prime.type_brain_prime(first_number)) |
| 50 | + print(question) |
| 51 | + answer = input('Your answer: ') |
| 52 | + if answer == str(correct_answer): |
| 53 | + number_of_successful_attempts += 1 |
| 54 | + print('Correct!') |
| 55 | + else: |
| 56 | + print(f"'{answer}' is wrong answer ;(. Correct answer was" |
| 57 | + f" '{correct_answer}'\n" |
| 58 | + f"Let's try again, {name}!") |
| 59 | + break |
| 60 | + if number_of_successful_attempts == NUMBERS_OF_ATTEMPTS: |
| 61 | + print(f'Congratulations, {name}!') |
0 commit comments