File tree Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ import prompt
2+
3+ from brain_games .cli import welcome_user
4+ from brain_games .scripts .brain_games import greet
5+
6+
7+ def get_conditions ():
8+ raise NotImplementedError ("Define get_conditions() in game module" )
9+
10+
11+ def engine_game ():
12+ greet ()
13+ name = welcome_user ()
14+ description = ''
15+ print (description )
16+
17+ answer = 0
18+ rounds = 3
19+
20+ while answer < rounds :
21+ question , correct_answer = get_conditions ()
22+ print (f'Question: { question } ' )
23+
24+ user_answer = prompt .string ('Your answer: ' )
25+
26+ if user_answer == correct_answer :
27+ print ('Correct!' )
28+ answer += 1
29+ else :
30+ print (f"'{ user_answer } ' is wrong answer ;(."
31+ f" Correct answer was '{ correct_answer } '." )
32+ print (f"Let's try again, { name } !" )
33+ break
34+ if answer == rounds :
35+ print (f'Congratulations, { name } !' )
Original file line number Diff line number Diff line change 1+ from random import choice , randrange
2+
3+ import prompt
4+
5+ from brain_games .cli import welcome_user
6+
7+
8+ def brain_calc ():
9+ name = welcome_user ()
10+ print ('What is the result of the expression?' )
11+
12+ answer = 0
13+ while answer < 3 :
14+ n1 = randrange (1 , 51 )
15+ n2 = randrange (1 , 51 )
16+ operator = choice (['+' , '-' , '*' ])
17+
18+ if operator == "+" :
19+ res = n1 + n2
20+ print (f'Question: { n1 } + { n2 } ' )
21+ elif operator == "-" :
22+ res = n1 - n2
23+ print (f'Question: { n1 } - { n2 } ' )
24+ elif operator == "*" :
25+ res = n1 * n2
26+ print (f'Question: { n1 } * { n2 } ' )
27+
28+ user_answer = prompt .integer ('Your answer: ' )
29+ if user_answer == res :
30+ print ('Correct!' )
31+ answer += 1
32+ else :
33+ print (f"'{ user_answer } ' is wrong answer ;(."
34+ f"Correct answer was '{ res } .'" )
35+ print (f"Let's try again, { name } !" )
36+ break
37+ if answer == 3 :
38+ print (f'Congratulations, { name } !' )
You can’t perform that action at this time.
0 commit comments