Skip to content

Commit

Permalink
refactor calc.py: add random.choise()
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Chasovskikh committed Apr 14, 2024
1 parent 5316d0d commit 8084918
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions brain_games/games/calc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from random import randrange
from random import randrange, choice

description = 'What is the result of the expression?'

Expand All @@ -10,14 +10,17 @@ def logic():
"""
number_1 = randrange(100)
number_2 = randrange(100)
operator = randrange(1, 4)
if operator == 1:
calc_perfect_answer = number_1 + number_2
question = f'{number_1} + {number_2}'
elif operator == 2:
calc_perfect_answer = number_1 - number_2
question = f'{number_1} - {number_2}'
else:
calc_perfect_answer = number_1 * number_2
question = f'{number_1} * {number_2}'
operator = choice(['+', '-', '*'])
question = f'{number_1} {operator} {number_2}'
calc_perfect_answer = eval(question)
# operator = randrange(1, 4)
# if operator == 1:
# calc_perfect_answer = number_1 + number_2
# question = f'{number_1} + {number_2}'
# elif operator == 2:
# calc_perfect_answer = number_1 - number_2
# question = f'{number_1} - {number_2}'
# else:
# calc_perfect_answer = number_1 * number_2
# question = f'{number_1} * {number_2}'
return question, str(calc_perfect_answer)

0 comments on commit 8084918

Please sign in to comment.