diff --git a/projects/Math Game/README.md b/projects/Math Game/README.md new file mode 100644 index 00000000..4ab67728 --- /dev/null +++ b/projects/Math Game/README.md @@ -0,0 +1,14 @@ +# Math Game +It's just a simple math game. Improve your math skills + +### Prerequisites +`import random` and `import operator` + +### How to run the script +`python math_game.py` + +### Screenshot/GIF showing the sample use of the script +![image](https://github.com/xNewz/python-mini-projects/blob/master/projects/Math%20Game/img.gif) + +## *Author Name* +https://github.com/xNewz diff --git a/projects/Math Game/img.gif b/projects/Math Game/img.gif new file mode 100644 index 00000000..01e20939 Binary files /dev/null and b/projects/Math Game/img.gif differ diff --git a/projects/Math Game/math_game.py b/projects/Math Game/math_game.py new file mode 100644 index 00000000..f2042640 --- /dev/null +++ b/projects/Math Game/math_game.py @@ -0,0 +1,35 @@ +import random +import operator + +def random_problem(): + operators = { + '+': operator.add, + '-': operator.sub, + '*': operator.mul, + '/': operator.truediv, + } + + num_1 = random.randint(1, 10) + num_2 = random.randint(1, 10) + operation = random.choice(list(operators.keys())) + answer = operators.get(operation)(num_1, num_2) + print(f'What is {num_1} {operation} {num_2}') + return answer + +def ask_question(): + answer = random_problem() + guess = float(input('Enter you answer: ')) + return guess == answer + +def game(): + score = 0 + while True: + if ask_question() == True: + score += 1 + print('Correct !') + else: + print('Incorrect') + break + print(f'======== Game Over ========\nYou score is {score}\nKepp going!') + +game() \ No newline at end of file