diff --git a/mathgenerator/computer_science.py b/mathgenerator/computer_science.py index c3a3898..bb39253 100644 --- a/mathgenerator/computer_science.py +++ b/mathgenerator/computer_science.py @@ -32,11 +32,11 @@ def binary_2s_complement(maxDigits=10): | Ex. Problem | Ex. Solution | | --- | --- | - | 2's complement of $1011 = $ | $101$ | + | 2's complement of $1011 = $ | $0101$ | """ digits = random.randint(1, maxDigits) question = ''.join([str(random.randint(0, 1)) - for i in range(digits)]).lstrip('0') + for i in range(digits)]) answer = [] for i in question: @@ -56,7 +56,7 @@ def binary_2s_complement(maxDigits=10): answer.insert(0, '1') problem = f"2's complement of ${question} = $" - solution = ''.join(answer).lstrip('0') + solution = ''.join(answer) return problem, f'${solution}$' diff --git a/mathgenerator/misc.py b/mathgenerator/misc.py index 80b6b13..b83eaf6 100644 --- a/mathgenerator/misc.py +++ b/mathgenerator/misc.py @@ -176,7 +176,7 @@ def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20): | Ex. Problem | Ex. Solution | | --- | --- | - | $19.42(-19.0\theta + i-4.0\theta)$ | $-2.93$ | + | Convert $-14.0+13.0i$ into polar form | $19.1(cos(2.39)+isin(2.39))$ | """ num = complex( random.randint(min_real_imaginary_num, max_real_imaginary_num), @@ -185,9 +185,13 @@ def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20): b = num.imag r = round(math.hypot(a, b), 2) theta = round(math.atan2(b, a), 2) + print(a) + print(b) - problem = rf'${r}({a}\theta + i{b}\theta)$' - return problem, f'${theta}$' + + solution = rf'${r}(cos({theta})+isin({theta}))$' + problem = rf'Convert ${a}+{b}i$ into polar form' + return problem, solution def decimal_to_roman_numerals(max_decimal=4000):