File tree Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Expand file tree Collapse file tree 2 files changed +5
-9
lines changed Original file line number Diff line number Diff line change 1- import secrets
21import operator
2+ import secrets
33
44
55def calculate (num1 : int , num2 : int , operation : str ) -> int :
66 """Calculate the result of two numbers with given operation."""
7- operations = {
8- '+' : operator .add ,
9- '-' : operator .sub ,
10- '*' : operator .mul
11- }
7+ operations = {"+" : operator .add , "-" : operator .sub , "*" : operator .mul }
128 return operations [operation ](num1 , num2 )
139
1410
1511def generate_round () -> tuple [str , str ]:
1612 """Generate a round for the calculator game."""
1713 num1 = secrets .randbelow (50 ) + 1 # 1-50
1814 num2 = secrets .randbelow (50 ) + 1 # 1-50
19- operation = secrets .choice (['+' , '-' , '*' ])
15+ operation = secrets .choice (["+" , "-" , "*" ])
2016
2117 question = f"{ num1 } { operation } { num2 } "
2218 correct_answer = str (calculate (num1 , num2 , operation ))
Original file line number Diff line number Diff line change 22from brain_games .engine import run_game
33from brain_games .games .calc import generate_round
44
5- DESCRIPTION = ' What is the result of the expression?'
5+ DESCRIPTION = " What is the result of the expression?"
66
77
88def main ():
99 run_game (DESCRIPTION , generate_round )
1010
1111
12- if __name__ == ' __main__' :
12+ if __name__ == " __main__" :
1313 main ()
You can’t perform that action at this time.
0 commit comments