Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Open
Changes from 1 commit
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
Next Next commit
Add math game
  • Loading branch information
xNewz committed Dec 1, 2021
commit 465a814eed10072949b5dab3aaf90fb01939dc7e
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()