Skip to content

Commit

Permalink
Merge pull request #983 from pratheekv39/feature/math_wizard
Browse files Browse the repository at this point in the history
#970 Added the Math Wizard Game
  • Loading branch information
UTSAVS26 authored Nov 1, 2024
2 parents bf71e02 + b227271 commit dce2c01
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
87 changes: 87 additions & 0 deletions Game_Development/Math Wizard Game/README.md
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! 🎉
63 changes: 63 additions & 0 deletions Game_Development/Math Wizard Game/main.py
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()
2 changes: 2 additions & 0 deletions Project-Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@
* [Main](Game_Development/Map%20Game/main.py)
* Mastermind
* [Mastermind](Game_Development/MasterMind/mastermind.py)
* Math Wizard Game
* [Main](Game_Development/Math%20Wizard%20Game/main.py)
* Maze
* [Maze](Game_Development/Maze/Maze.py)
* Memory Typing Game
Expand Down

0 comments on commit dce2c01

Please sign in to comment.