Added documentation comments
This commit is contained in:
+25
-2
@@ -7,10 +7,33 @@ from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
|
||||
def format_and_return(a, b, operation, result):
|
||||
a_str, b_str = str(a).rjust(2, ' '), str(b).rjust(2, ' ')
|
||||
return f"{a_str} {operation} {b_str} =", result
|
||||
"""
|
||||
Formats and returns a math problem string along with its result.
|
||||
|
||||
Args:
|
||||
a (int): The first operand in the math problem.
|
||||
b (int): The second operand in the math problem.
|
||||
operation (str): The mathematical operation ('+', '-', '*', '/') to be performed.
|
||||
result (int): The result of the math problem.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the formatted math problem string and its result.
|
||||
"""
|
||||
a_str, b_str = str(a).rjust(2, ' '), str(b).rjust(2, ' ')
|
||||
return f"{a_str} {operation} {b_str} =", result
|
||||
|
||||
def generate_math_problem():
|
||||
"""
|
||||
Generates a random math problem with an operation chosen from addition, subtraction, multiplication, or division.
|
||||
|
||||
The operands are randomly generated integers, with the following constraints:
|
||||
- Both operands are within the range [0, 20] for addition and subtraction.
|
||||
- Both operands are within the range [0, 20] for multiplication.
|
||||
- For division, the divisor is within the range [1, 5] and the dividend is a multiple of the divisor, within the range [1, 40].
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the formatted math problem string and the correct result (integer).
|
||||
"""
|
||||
operation = random.choice(['+', '-', '*', '/'])
|
||||
a, b = random.randint(0, 20), random.randint(0, 20)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user