Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Math Game #279

Open
wants to merge 2 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
6 changes: 6 additions & 0 deletions Simple Math Game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Simple_Math_Game

- It is a simple mathematical game with a graphical user interface (GUI).
- In this game, you will be given five problems to solve.
- The problem set includes addition, subtraction, division, multiplication, and modulus operations.
- At the end of the game, you will see your score and the time taken to solve the five problems.
56 changes: 56 additions & 0 deletions Simple Math Game/Simple Math Game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import random
import time
import easygui

score = 0
start_time = time.time()

for i in range(1,6):

first_number = random.randint(1,10)
second_number = random.randint(1,10)
operators = ['+','-','/','%','*']
selected_operator = random.choice(operators)

message = "Problem",i,"->", first_number, selected_operator, second_number
user_answer = easygui.enterbox(message,"Enter your answer:")

if selected_operator == '+':
result = first_number + second_number
if result == eval(user_answer):
score = score+1
else:
print("Answer is:-",result)

elif selected_operator == '-':
result = first_number - second_number
if result == eval(user_answer):
score = score+1
else:
print("Answer is:-",result)

elif selected_operator == '/':
result = round(first_number / second_number,1)
if result == eval(user_answer):
score = score+1
else:
print("Answer is:-",result)

elif selected_operator == '%':
result = first_number % second_number
if result == eval(user_answer):
score = score+1
else:
print("Answer is:-",result)

elif selected_operator == '*':
result = first_number * second_number
if result == eval(user_answer):
score = score+1
else:
print("Answer is:-",result)

end_time = time.time()
final_time = round(end_time - start_time,2)
result_message = (f"You have scored {score} points in {final_time} seconds.")
easygui.msgbox(result_message, "Result")