Maths Problem Generator
import random
Maths Problem Generator in Python – Description
A Maths Problem Generator is a Python program designed to automatically create random arithmetic problems for practice, quizzes, or learning purposes. The program can generate problems involving basic arithmetic operations like addition, subtraction, multiplication, and division. It can also check the user’s answer and provide immediate feedback.
Key Features:
1. Random Problem Generation – Uses Python’s random module to generate numbers within a specified range.
2. Multiple Operations – Supports addition (+), subtraction (-), multiplication (×), and division (÷).
3. User Interaction – Prompts the user to solve each problem and enter an answer.
4. Automatic Evaluation – Compares the user’s input with the correct answer and provides feedback.
5. Customizable Difficulty – Users can adjust the range of numbers or the type of operations to increase or decrease difficulty.
6. Score Tracking (Optional) – Can keep track of correct and incorrect answers to help monitor progress.
OPERATORS = ["+","*","/","-"]
MIN_OPERAND = 3
MAX_OPERAND = 12
TOTAL_PROBLEMS = 10
def generate_problem():
left = random.randint(MIN_OPERAND,MAX_OPERAND)
right = random.randint(MIN_OPERAND,MAX_OPERAND)
operators = random.choice(OPERATORS)
express = str(left) + " "+operators+ " " + str(right)
answer = eval(express)
return express, answer
for i in range(TOTAL_PROBLEMS):
express, answer = generate_problem()
while True:
guess = input("problem"+str(i+1)+ ":" +express+" " + "=")
if guess == str(answer):
break
Comments
Post a Comment