forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_math_game.py
38 lines (30 loc) · 1015 Bytes
/
simple_math_game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Imports
import pyinputplus as pyip
from random import choice
# Variables
questionTypes = ['+', '-', '*', '/', '**']
numbersRange = [num for num in range(1, 20)]
points = 0
# Hints
print('Round down to one Number after the Comma.')
print('When asked to press enter to continue, type stop to stop.\n')
# Game Loop
while True:
# Deciding and generating question
currenType = choice(questionTypes)
promptEquation = str(choice(numbersRange)) + ' ' + currenType + ' ' + str(choice(numbersRange))
solution = round(eval(promptEquation), 1)
# Getting answer from User
answer = pyip.inputNum(prompt=promptEquation + ' = ')
# Feedback and Points
if answer == solution:
points += 1
print('Correct!\nPoints: ',points)
else:
points -= 1
print('Wrong!\nSolution: '+str(solution)+'\nPoints: ',points)
# Stopping the Game
if pyip.inputStr('Press "Enter" to continue', blank=True) == 'stop':
break
# Some Padding
print('\n\n')