From 79d5af0aeae16987fb022b5382ffcb857b98739b Mon Sep 17 00:00:00 2001 From: ryuk-jayant Date: Fri, 18 Oct 2024 17:12:34 +0530 Subject: [PATCH] fix power_rule_differentiation --- mathgenerator/calculus.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mathgenerator/calculus.py b/mathgenerator/calculus.py index 42196c3..942d5aa 100644 --- a/mathgenerator/calculus.py +++ b/mathgenerator/calculus.py @@ -42,8 +42,15 @@ def power_rule_differentiation(max_coef=10, max_exp=10, max_terms=5): coefficient = random.randint(1, max_coef) exponent = random.randint(1, max_exp) - problem += f'{coefficient}x^{{{exponent}}}' - solution += f'{coefficient * exponent}x^{{{exponent - 1}}}' + problem += f'{coefficient}x^{{{exponent}}}' if exponent>1 else f'{coefficient}x' + # solution += f'{coefficient * exponent}x^{{{exponent - 1}}}' + if exponent==1: + solution+=f'{coefficient * exponent}' + elif exponent==2: + solution+=f'{coefficient * exponent}x' + else: + solution+=f'{coefficient * exponent}x^{{{exponent - 1}}}' + return problem + '$', solution + '$'