Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

math_game #546

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions projects/Math Game/README.md
Original file line number Diff line number Diff line change
@@ -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
Binary file added projects/Math Game/img.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions projects/Math Game/math_game.py
Original file line number Diff line number Diff line change
@@ -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()