-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #983 from pratheekv39/feature/math_wizard
#970 Added the Math Wizard Game
- Loading branch information
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Math Wizard 🧙♂️ | ||
|
||
This is a simple **Python-based command-line** game called **Math Wizard**, where players are presented with random math equations and must solve as many as possible within a set time limit. The game is designed to test your math skills and quick thinking under pressure! | ||
|
||
--- | ||
|
||
## 🎯 Objective | ||
|
||
The goal is to solve as many randomly generated math equations (addition, subtraction, multiplication, and division) as possible within a 60-second time limit. Each correct answer increases your score. | ||
|
||
--- | ||
|
||
## 🚀 How to Play | ||
|
||
1. **Start the Game**: Run the Python script to begin. | ||
2. **Solve the Equation**: A random math equation will be displayed. Enter the correct answer when prompted. | ||
3. **Receive Feedback**: After each answer: | ||
- If correct, your score will increase. | ||
- If incorrect, the correct answer will be shown, and the next question will be generated. | ||
4. **Time Limit**: You have 60 seconds to answer as many equations as possible. | ||
5. **View Final Score**: Once time is up, your total score will be displayed. | ||
6. **Play Again**: You can choose to play another round or exit the game. | ||
|
||
--- | ||
|
||
## 🛠 System Requirements | ||
|
||
- **Operating System**: Any system running Python 3.x | ||
- **Python Version**: Python 3.x or higher | ||
|
||
### Dependencies | ||
|
||
This game uses only Python's built-in libraries, so no additional dependencies are required. | ||
|
||
--- | ||
|
||
## 🔧 How to Run | ||
|
||
1. Clone the repository and navigate to the project folder: | ||
```bash | ||
git clone <repository-url> | ||
cd <project-folder> | ||
``` | ||
|
||
2. Run the Python script: | ||
```bash | ||
python3 main.py | ||
``` | ||
|
||
3. Enjoy playing Math Wizard and test your math skills! | ||
|
||
--- | ||
|
||
## 📚 Game Mechanics | ||
|
||
- **Math Equations**: The game generates random math equations using addition (+), subtraction (-), multiplication (*), and division (/). Division results are always whole numbers. | ||
- **User Input**: You will enter your answer as an integer. | ||
- **Feedback**: | ||
- Correct answers increase your score. | ||
- Incorrect answers show the correct result. | ||
- **Time Limit**: You have 60 seconds to answer as many equations as possible. | ||
- **Final Score**: The game will display your score after the time runs out. | ||
|
||
--- | ||
|
||
## 💻 System Specifications | ||
|
||
- Python Version: 3.x+ | ||
- OS: Any system capable of running Python 3.x | ||
|
||
--- | ||
|
||
## 📖 Additional Information | ||
|
||
Math Wizard is a fast-paced game that sharpens your mental math abilities while having fun. It's a great way to practice arithmetic under a time constraint and can be an excellent educational tool for improving quick calculation skills. | ||
|
||
--- | ||
|
||
## 🤔 Strategy Tips | ||
|
||
1. Focus on getting correct answers quickly—every second counts. | ||
2. If you're not sure of an answer, it's better to make an educated guess than to spend too much time thinking. | ||
3. Division questions always result in whole numbers, so no need to worry about fractions. | ||
|
||
--- | ||
|
||
Have fun playing Math Wizard and see how high you can score! 🎉 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import random | ||
import time | ||
|
||
# Function to generate a random math question | ||
def generate_question(): | ||
operations = ['+', '-', '*', '/'] | ||
num1 = random.randint(1, 100) | ||
num2 = random.randint(1, 100) | ||
operation = random.choice(operations) | ||
|
||
# Ensure no division by zero | ||
if operation == '/': | ||
num1 = num1 * num2 # Ensure division gives a whole number | ||
|
||
# Create the question and calculate the correct answer | ||
if operation == '+': | ||
answer = num1 + num2 | ||
elif operation == '-': | ||
answer = num1 - num2 | ||
elif operation == '*': | ||
answer = num1 * num2 | ||
elif operation == '/': | ||
answer = num1 // num2 # Perform integer division | ||
|
||
return f"{num1} {operation} {num2}", answer | ||
|
||
# Function to start the game | ||
def start_game(): | ||
score = 0 | ||
total_questions = 0 | ||
time_limit = 60 # 60 seconds for the game | ||
start_time = time.time() # Get the current time | ||
|
||
print("Welcome to Math Wizard!") | ||
print("Solve as many math equations as you can in 60 seconds.\n") | ||
|
||
while time.time() - start_time < time_limit: | ||
# Generate a random question | ||
question, correct_answer = generate_question() | ||
print(f"Question: {question}") | ||
|
||
try: | ||
# Get player's answer | ||
player_answer = int(input("Your answer: ")) | ||
|
||
# Check if the answer is correct | ||
if player_answer == correct_answer: | ||
print("Correct!\n") | ||
score += 1 | ||
else: | ||
print(f"Incorrect! The correct answer was {correct_answer}\n") | ||
|
||
total_questions += 1 | ||
|
||
except ValueError: | ||
print("Please enter a valid number!\n") | ||
|
||
# End of game, print the result | ||
print(f"\nTime's up! You solved {score} out of {total_questions} questions correctly.") | ||
print(f"Your final score is: {score}") | ||
|
||
if __name__ == "__main__": | ||
start_game() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters