Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mathgenerator/computer_science.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}$'


Expand Down
10 changes: 7 additions & 3 deletions mathgenerator/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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):
Expand Down