File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import random
2
+ import operator
3
+
4
+ def random_problem ():
5
+ operators = {
6
+ '+' : operator .add ,
7
+ '-' : operator .sub ,
8
+ '*' : operator .mul ,
9
+ '/' : operator .truediv ,
10
+ }
11
+
12
+ num_1 = random .randint (1 , 10 )
13
+ num_2 = random .randint (1 , 10 )
14
+
15
+ operation = random .choice (list (operators .keys ()))
16
+ answer = operators .get (operation )(num_1 , num_2 )
17
+ print (f'What is { num_1 } { operation } { num_2 } ' )
18
+ return answer
19
+
20
+ def ask_question ():
21
+ answer = int (random_problem ())
22
+ guess = float (input ('Enter you answer: ' ))
23
+ return guess == answer
24
+
25
+ def game ():
26
+ score = 0
27
+ while True :
28
+ if ask_question () == True :
29
+ score += 1
30
+ print ('Correct !' )
31
+ else :
32
+ print ('Incorrect' )
33
+ break
34
+ print (f'======== Game Over ========\n You score is { score } \n Kepp going!' )
35
+
36
+ game ()
You can’t perform that action at this time.
0 commit comments