yapf lint

This commit is contained in:
lukew3
2023-06-02 10:31:59 -04:00
parent c6ddbbade9
commit 966419d04c
13 changed files with 108 additions and 108 deletions

View File

@@ -131,5 +131,5 @@ gen_list = [
("area_of_trapezoid", "geometry"), ("area_of_trapezoid", "geometry"),
("tribonacci_series", "computer_science"), ("tribonacci_series", "computer_science"),
("nth_tribonacci_number", "computer_science"), ("nth_tribonacci_number", "computer_science"),
("velocity_of_object","misc"), ("velocity_of_object", "misc"),
] ]

View File

@@ -45,10 +45,12 @@ def combine_like_terms(max_coef=10, max_exp=20, max_terms=10):
numTerms = random.randint(1, max_terms) numTerms = random.randint(1, max_terms)
coefs = [random.randint(1, max_coef) for _ in range(numTerms)] coefs = [random.randint(1, max_coef) for _ in range(numTerms)]
exponents = [random.randint(1, max(max_exp - 1, 2)) exponents = [
for _ in range(numTerms)] random.randint(1, max(max_exp - 1, 2)) for _ in range(numTerms)
]
problem = " + ".join([f"{coefs[i]}x^{{{exponents[i]}}}" for i in range(numTerms)]) problem = " + ".join(
[f"{coefs[i]}x^{{{exponents[i]}}}" for i in range(numTerms)])
d = {} d = {}
for i in range(numTerms): for i in range(numTerms):
if exponents[i] in d: if exponents[i] in d:
@@ -133,9 +135,7 @@ def complex_quadratic(prob_type=0, max_range=10):
return problem, solution return problem, solution
def compound_interest(max_principle=10000, def compound_interest(max_principle=10000, max_rate=10, max_time=10):
max_rate=10,
max_time=10):
r"""Compound Interest r"""Compound Interest
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -165,17 +165,14 @@ def distance_two_points(max_val_xy=20, min_val_xy=-20):
point2X = random.randint(min_val_xy, max_val_xy + 1) point2X = random.randint(min_val_xy, max_val_xy + 1)
point2Y = random.randint(min_val_xy, max_val_xy + 1) point2Y = random.randint(min_val_xy, max_val_xy + 1)
distanceSq = (point1X - point2X) ** 2 + (point1Y - point2Y) ** 2 distanceSq = (point1X - point2X)**2 + (point1Y - point2Y)**2
solution = rf"$\sqrt{{{distanceSq}}}$" solution = rf"$\sqrt{{{distanceSq}}}$"
problem = f"Find the distance between $({point1X}, {point1Y})$ and $({point2X}, {point2Y})$" problem = f"Find the distance between $({point1X}, {point1Y})$ and $({point2X}, {point2Y})$"
return problem, solution return problem, solution
def expanding(range_x1=10, def expanding(range_x1=10, range_x2=10, range_a=10, range_b=10):
range_x2=10,
range_a=10,
range_b=10):
r"""Expanding Factored Binomial r"""Expanding Factored Binomial
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -340,10 +337,10 @@ def intersection_of_two_lines(min_m=-10,
x = rf"\frac{{{x.numerator}}}{{{x.denominator}}}" x = rf"\frac{{{x.numerator}}}{{{x.denominator}}}"
return x return x
m1 = (random.randint(min_m, m1 = (random.randint(min_m, max_m),
max_m), random.randint(min_denominator, max_denominator)) random.randint(min_denominator, max_denominator))
m2 = (random.randint(min_m, m2 = (random.randint(min_m, max_m),
max_m), random.randint(min_denominator, max_denominator)) random.randint(min_denominator, max_denominator))
b1 = random.randint(min_b, max_b) b1 = random.randint(min_b, max_b)
b2 = random.randint(min_b, max_b) b2 = random.randint(min_b, max_b)
@@ -409,7 +406,8 @@ def invert_matrix(square_matrix_dimension=3,
for i in range(1, square_matrix_dimension - 1): for i in range(1, square_matrix_dimension - 1):
Mat[i] = [ Mat[i] = [
sum(i) for i in zip(Mat[square_matrix_dimension - 1], Mat[i]) sum(i)
for i in zip(Mat[square_matrix_dimension - 1], Mat[i])
] ]
isItOk = True isItOk = True
@@ -437,7 +435,8 @@ def invert_matrix(square_matrix_dimension=3,
square_matrix_dimension * square_matrix_dimension) square_matrix_dimension * square_matrix_dimension)
randomlist = list(set(randomlist) - set(plist)) randomlist = list(set(randomlist) - set(plist))
n_list = random.sample( n_list = random.sample(
randomlist, square_matrix_dimension * (square_matrix_dimension - 1)) randomlist,
square_matrix_dimension * (square_matrix_dimension - 1))
Mat = list() Mat = list()
for i in range(0, square_matrix_dimension): for i in range(0, square_matrix_dimension):
z = list() z = list()
@@ -504,7 +503,9 @@ def line_equation_from_2_points(max_val=20):
y2 = random.randint(-max_val, max_val) y2 = random.randint(-max_val, max_val)
m1 = (y2 - y1) // math.gcd(y2 - y1, x2 - x1) m1 = (y2 - y1) // math.gcd(y2 - y1, x2 - x1)
m2 = (x2 - x1) // math.gcd(y2 - y1, x2 - x1) m2 = (x2 - x1) // math.gcd(y2 - y1, x2 - x1)
c1 = (y1 * (x2 - x1) - (y2 - y1) * x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1)) c1 = (y1 * (x2 - x1) -
(y2 - y1) * x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1,
(x2 - x1))
c2 = (x2 - x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1)) c2 = (x2 - x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1))
c = rf"{'+' if c1 >= 0 else '-'}\frac{{{abs(c1)}}}{{{c2}}}" if c1 != 0 else "" c = rf"{'+' if c1 >= 0 else '-'}\frac{{{abs(c1)}}}{{{c2}}}" if c1 != 0 else ""
if c2 < 0: if c2 < 0:
@@ -605,9 +606,11 @@ def multiply_complex_numbers(min_real_imaginary_num=-20,
| --- | --- | | --- | --- |
| $(14+18j) * (14+15j) = $ | $(-74+462j)$ | | $(14+18j) * (14+15j) = $ | $(-74+462j)$ |
""" """
num1 = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num), num1 = complex(
random.randint(min_real_imaginary_num, max_real_imaginary_num),
random.randint(min_real_imaginary_num, max_real_imaginary_num)) random.randint(min_real_imaginary_num, max_real_imaginary_num))
num2 = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num), num2 = complex(
random.randint(min_real_imaginary_num, max_real_imaginary_num),
random.randint(min_real_imaginary_num, max_real_imaginary_num)) random.randint(min_real_imaginary_num, max_real_imaginary_num))
product = num1 * num2 product = num1 * num2
@@ -652,7 +655,8 @@ def quadratic_equation(max_val=100):
a = random.randint(1, max_val) a = random.randint(1, max_val)
c = random.randint(1, max_val) c = random.randint(1, max_val)
b = random.randint( b = random.randint(
round(math.sqrt(4 * a * c)) + 1, round(math.sqrt(4 * max_val * max_val))) round(math.sqrt(4 * a * c)) + 1,
round(math.sqrt(4 * max_val * max_val)))
D = math.sqrt(b * b - 4 * a * c) D = math.sqrt(b * b - 4 * a * c)
res = {round((-b + D) / (2 * a), 2), round((-b - D) / (2 * a), 2)} res = {round((-b + D) / (2 * a), 2), round((-b - D) / (2 * a), 2)}
@@ -661,9 +665,7 @@ def quadratic_equation(max_val=100):
return problem, solution return problem, solution
def simple_interest(max_principle=10000, def simple_interest(max_principle=10000, max_rate=10, max_time=10):
max_rate=10,
max_time=10):
r"""Simple Interest r"""Simple Interest
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -680,9 +682,7 @@ def simple_interest(max_principle=10000,
return problem, solution return problem, solution
def system_of_equations(range_x=10, def system_of_equations(range_x=10, range_y=10, coeff_mult_range=10):
range_y=10,
coeff_mult_range=10):
r"""Solve a System of Equations in R^2 r"""Solve a System of Equations in R^2
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |

View File

@@ -75,7 +75,9 @@ def cube_root(min_no=1, max_no=1000):
b = random.randint(min_no, max_no) b = random.randint(min_no, max_no)
a = b**(1 / 3) a = b**(1 / 3)
return (rf"What is the cube root of: $\sqrt[3]{{{b}}}=$ to 2 decimal places?", f"${round(a, 2)}$") return (
rf"What is the cube root of: $\sqrt[3]{{{b}}}=$ to 2 decimal places?",
f"${round(a, 2)}$")
def divide_fractions(max_val=10): def divide_fractions(max_val=10):
@@ -215,7 +217,6 @@ def greatest_common_divisor(numbers_count=2, max_num=10**3):
| --- | --- | | --- | --- |
| $GCD(488075608, 75348096)=$ | $8$ | | $GCD(488075608, 75348096)=$ | $8$ |
""" """
def greatestCommonDivisorOfTwoNumbers(number1, number2): def greatestCommonDivisorOfTwoNumbers(number1, number2):
number1 = abs(number1) number1 = abs(number1)
number2 = abs(number2) number2 = abs(number2)
@@ -224,8 +225,7 @@ def greatest_common_divisor(numbers_count=2, max_num=10**3):
return number1 return number1
numbers_count = max(numbers_count, 2) numbers_count = max(numbers_count, 2)
numbers = [random.randint(0, max_num) numbers = [random.randint(0, max_num) for _ in range(numbers_count)]
for _ in range(numbers_count)]
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers( greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[0], numbers[1]) numbers[0], numbers[1])
@@ -373,7 +373,7 @@ def square(max_square_num=20):
| $17^2=$ | $289$ | | $17^2=$ | $289$ |
""" """
a = random.randint(1, max_square_num) a = random.randint(1, max_square_num)
b = a ** 2 b = a**2
return f'${a}^2=$', f'${b}$' return f'${a}^2=$', f'${b}$'
@@ -386,7 +386,7 @@ def square_root(min_no=1, max_no=12):
| $\sqrt{64}=$ | $8$ | | $\sqrt{64}=$ | $8$ |
""" """
b = random.randint(min_no, max_no) b = random.randint(min_no, max_no)
a = b ** 2 a = b**2
return rf'$\sqrt{{{a}}}=$', f'${b}$' return rf'$\sqrt{{{a}}}=$', f'${b}$'
@@ -412,9 +412,9 @@ def simplify_square_root(max_variable=100):
a = b = 1 a = b = 1
for i in factors.keys(): for i in factors.keys():
if factors[i] & 1 == 0: if factors[i] & 1 == 0:
a *= i ** (factors[i] // 2) a *= i**(factors[i] // 2)
else: else:
a *= i ** ((factors[i] - 1) // 2) a *= i**((factors[i] - 1) // 2)
b *= i b *= i
if a == 1 or b == 1: if a == 1 or b == 1:
return simplify_square_root(max_variable) return simplify_square_root(max_variable)

View File

@@ -24,9 +24,7 @@ def definite_integral(max_coef=100):
return problem, f'${solution}$' return problem, f'${solution}$'
def power_rule_differentiation(max_coef=10, def power_rule_differentiation(max_coef=10, max_exp=10, max_terms=5):
max_exp=10,
max_terms=5):
r"""Power Rule Differentiation r"""Power Rule Differentiation
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -50,9 +48,7 @@ def power_rule_differentiation(max_coef=10,
return problem + '$', solution + '$' return problem + '$', solution + '$'
def power_rule_integration(max_coef=10, def power_rule_integration(max_coef=10, max_exp=10, max_terms=5):
max_exp=10,
max_terms=5):
r"""Power Rule Integration r"""Power Rule Integration
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |

View File

@@ -67,8 +67,9 @@ def binary_complement_1s(maxDigits=10):
| --- | --- | | --- | --- |
| $1111001 = $ | $0000110$ | | $1111001 = $ | $0000110$ |
""" """
question = ''.join([str(random.randint(0, 1)) question = ''.join([
for _ in range(random.randint(1, maxDigits))]) str(random.randint(0, 1)) for _ in range(random.randint(1, maxDigits))
])
answer = ''.join(["0" if digit == "1" else "1" for digit in question]) answer = ''.join(["0" if digit == "1" else "1" for digit in question])
problem = f'${question} = $' problem = f'${question} = $'
@@ -82,8 +83,8 @@ def binary_to_decimal(max_dig=10):
| --- | --- | | --- | --- |
| $000110$ | $6$ | | $000110$ | $6$ |
""" """
problem = ''.join([str(random.randint(0, 1)) problem = ''.join(
for _ in range(random.randint(1, max_dig))]) [str(random.randint(0, 1)) for _ in range(random.randint(1, max_dig))])
solution = f'${int(problem, 2)}$' solution = f'${int(problem, 2)}$'
return f'${problem}$', solution return f'${problem}$', solution
@@ -95,8 +96,8 @@ def binary_to_hex(max_dig=10):
| --- | --- | | --- | --- |
| $010101$ | $0x15$ | | $010101$ | $0x15$ |
""" """
problem = ''.join([str(random.randint(0, 1)) problem = ''.join(
for _ in range(random.randint(1, max_dig))]) [str(random.randint(0, 1)) for _ in range(random.randint(1, max_dig))])
solution = f'${hex(int(problem, 2))}$' solution = f'${hex(int(problem, 2))}$'
return f'${problem}$', solution return f'${problem}$', solution
@@ -233,15 +234,16 @@ def nth_tribonacci_number(min_length=1, max_length=80):
| What is the 14th Tribonacci number? | $504$ | | What is the 14th Tribonacci number? | $504$ |
""" """
tribDict = {0:0, 1:0, 2:1} tribDict = {0: 0, 1: 0, 2: 1}
def recTrib(i): def recTrib(i):
if i not in tribDict: if i not in tribDict:
tribDict[i] = recTrib(i-1) + recTrib(i-2) + recTrib(i-3) tribDict[i] = recTrib(i - 1) + recTrib(i - 2) + recTrib(i - 3)
return tribDict[i] return tribDict[i]
n = random.randint(min_length, max_length) n = random.randint(min_length, max_length)
problem = f"What is the {n}th Tribonacci number?" problem = f"What is the {n}th Tribonacci number?"
solution = recTrib(n-1) solution = recTrib(n - 1)
return problem, f'${solution}$' return problem, f'${solution}$'
@@ -253,12 +255,15 @@ def tribonacci_series(min_length=1, max_length=80):
| The Tribonacci Series of the first $8$ numbers is ? | $0, 0, 1, 1, 2, 4, 7, 13$ | | The Tribonacci Series of the first $8$ numbers is ? | $0, 0, 1, 1, 2, 4, 7, 13$ |
""" """
tribDict = {0:0, 1:0, 2:1} tribDict = {0: 0, 1: 0, 2: 1}
def createTribSeries(i): def createTribSeries(i):
tribSeries = [] tribSeries = []
for idx in range(i): for idx in range(i):
if idx not in tribDict: if idx not in tribDict:
tribDict[idx] = tribDict[idx-1] + tribDict[idx-2] + tribDict[idx-3] tribDict[idx] = tribDict[idx -
1] + tribDict[idx -
2] + tribDict[idx - 3]
tribSeries.append(tribDict[idx]) tribSeries.append(tribDict[idx])
return tribSeries return tribSeries

View File

@@ -166,8 +166,10 @@ def basic_trigonometry(angles=[0, 30, 45, 60, 90],
1.73: r"\sqrt{3}", 1.73: r"\sqrt{3}",
} }
solution = result_fraction_map[round(eval(expression), 2)] if round( solution = result_fraction_map[round(
eval(expression), 2) <= 99999 else r"\infty" # for handling the ∞ condition eval(expression),
2)] if round(eval(expression),
2) <= 99999 else r"\infty" # for handling the ∞ condition
return problem, f'${solution}$' return problem, f'${solution}$'
@@ -346,7 +348,7 @@ def pythagorean_theorem(max_length=20):
""" """
a = random.randint(1, max_length) a = random.randint(1, max_length)
b = random.randint(1, max_length) b = random.randint(1, max_length)
c = round((a ** 2 + b ** 2) ** 0.5, 2) c = round((a**2 + b**2)**0.5, 2)
problem = f"What is the hypotenuse of a right triangle given the other two sides have lengths ${a}$ and ${b}$?" problem = f"What is the hypotenuse of a right triangle given the other two sides have lengths ${a}$ and ${b}$?"
solution = f"${c}$" solution = f"${c}$"
@@ -420,7 +422,7 @@ def surface_area_cube(max_side=20, unit='m'):
| Surface area of cube with side $= 6m$ is | $216 m^2$ | | Surface area of cube with side $= 6m$ is | $216 m^2$ |
""" """
a = random.randint(1, max_side) a = random.randint(1, max_side)
ans = 6 * (a ** 2) ans = 6 * (a**2)
problem = f"Surface area of cube with side $= {a}{unit}$ is" problem = f"Surface area of cube with side $= {a}{unit}$ is"
solution = f"${ans} {unit}^2$" solution = f"${ans} {unit}^2$"
@@ -468,14 +470,8 @@ def surface_area_pyramid(unit='m'):
| Surface area of pyramid with base length $= 30m$, base width $= 40m$, and height $= 25m$ is | $2400 m^2$ | | Surface area of pyramid with base length $= 30m$, base width $= 40m$, and height $= 25m$ is | $2400 m^2$ |
""" """
# List of Pythagorean triplets # List of Pythagorean triplets
_PYTHAGOREAN = [(3, 4, 5), _PYTHAGOREAN = [(3, 4, 5), (6, 8, 10), (9, 12, 15), (12, 16, 20),
(6, 8, 10), (15, 20, 25), (5, 12, 13), (10, 24, 26), (7, 24, 25)]
(9, 12, 15),
(12, 16, 20),
(15, 20, 25),
(5, 12, 13),
(10, 24, 26),
(7, 24, 25)]
# Generate first triplet # Generate first triplet
height, half_width, triangle_height_1 = random.sample( height, half_width, triangle_height_1 = random.sample(
@@ -628,7 +624,7 @@ def volume_cone_frustum(max_r1=20, max_r2=20, max_height=50, unit='m'):
h = random.randint(1, max_height) h = random.randint(1, max_height)
r1 = random.randint(1, max_r1) r1 = random.randint(1, max_r1)
r2 = random.randint(1, max_r2) r2 = random.randint(1, max_r2)
ans = round(((math.pi * h) * (r1 ** 2 + r2 ** 2 + r1 * r2)) / 3, 2) ans = round(((math.pi * h) * (r1**2 + r2**2 + r1 * r2)) / 3, 2)
problem = f"Volume of frustum with height $= {h}{unit}$ and $r1 = {r1}{unit}$ is and $r2 = {r2}{unit}$ is " problem = f"Volume of frustum with height $= {h}{unit}$ and $r1 = {r1}{unit}$ is and $r2 = {r2}{unit}$ is "
solution = f"${ans} {unit}^3$" solution = f"${ans} {unit}^3$"

View File

@@ -3,9 +3,7 @@ import math
import numpy as np import numpy as np
def arithmetic_progression_sum(max_d=100, def arithmetic_progression_sum(max_d=100, max_a=100, max_n=100):
max_a=100,
max_n=100):
"""Arithmetic Progression Sum """Arithmetic Progression Sum
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -25,9 +23,7 @@ def arithmetic_progression_sum(max_d=100,
return problem, f'${solution}$' return problem, f'${solution}$'
def arithmetic_progression_term(max_d=100, def arithmetic_progression_term(max_d=100, max_a=100, max_n=100):
max_a=100,
max_n=100):
"""Arithmetic Progression Term """Arithmetic Progression Term
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -175,15 +171,15 @@ def common_factors(max_val=100):
return problem, solution return problem, solution
def complex_to_polar(min_real_imaginary_num=-20, def complex_to_polar(min_real_imaginary_num=-20, max_real_imaginary_num=20):
max_real_imaginary_num=20):
r"""Complex to polar form r"""Complex to polar form
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
| --- | --- | | --- | --- |
| $19.42(-19.0\theta + i-4.0\theta)$ | $-2.93$ | | $19.42(-19.0\theta + i-4.0\theta)$ | $-2.93$ |
""" """
num = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num), num = complex(
random.randint(min_real_imaginary_num, max_real_imaginary_num),
random.randint(min_real_imaginary_num, max_real_imaginary_num)) random.randint(min_real_imaginary_num, max_real_imaginary_num))
a = num.real a = num.real
b = num.imag b = num.imag
@@ -224,7 +220,8 @@ def decimal_to_roman_numerals(max_decimal=4000):
elif last_value == 4: elif last_value == 4:
solution += (roman_dict[div] + roman_dict[div * 5]) solution += (roman_dict[div] + roman_dict[div * 5])
elif 5 <= last_value <= 8: elif 5 <= last_value <= 8:
solution += (roman_dict[div * 5] + (roman_dict[div] * (last_value - 5))) solution += (roman_dict[div * 5] + (roman_dict[div] *
(last_value - 5)))
elif last_value == 9: elif last_value == 9:
solution += (roman_dict[div] + roman_dict[div * 10]) solution += (roman_dict[div] + roman_dict[div * 10])
x = math.floor(x % div) x = math.floor(x % div)
@@ -288,7 +285,7 @@ def geometric_mean(max_value=100, max_count=4):
nums = [random.randint(1, max_value) for i in range(count)] nums = [random.randint(1, max_value) for i in range(count)]
product = np.prod(nums) product = np.prod(nums)
ans = round(product ** (1 / count), 2) ans = round(product**(1 / count), 2)
problem = f"Geometric mean of ${count}$ numbers ${nums} = $" problem = f"Geometric mean of ${count}$ numbers ${nums} = $"
# solution = rf"$({'*'.join(map(str, nums))}^{{\frac{{1}}{{{count}}}}} = {ans}$" # solution = rf"$({'*'.join(map(str, nums))}^{{\frac{{1}}{{{count}}}}} = {ans}$"
solution = f"${ans}$" solution = f"${ans}$"
@@ -436,10 +433,14 @@ def product_of_scientific_notations(min_exp_val=-100, max_exp_val=100):
| --- | --- | | --- | --- |
| Product of scientific notations $5.11 \times 10^{67}$ and $3.64 \times 10^{-59} = $ | $1.86 \times 10^{9}$ | | Product of scientific notations $5.11 \times 10^{67}$ and $3.64 \times 10^{-59} = $ | $1.86 \times 10^{9}$ |
""" """
a = [round(random.uniform(1, 10), 2), a = [
random.randint(min_exp_val, max_exp_val)] round(random.uniform(1, 10), 2),
b = [round(random.uniform(1, 10), 2), random.randint(min_exp_val, max_exp_val)
random.randint(min_exp_val, max_exp_val)] ]
b = [
round(random.uniform(1, 10), 2),
random.randint(min_exp_val, max_exp_val)
]
c = [a[0] * b[0], a[1] + b[1]] c = [a[0] * b[0], a[1] + b[1]]
if c[0] >= 10: if c[0] >= 10:
@@ -482,7 +483,7 @@ def quotient_of_power_same_base(max_base=50, max_power=10):
power1 = random.randint(1, max_power) power1 = random.randint(1, max_power)
power2 = random.randint(1, max_power) power2 = random.randint(1, max_power)
step = power1 - power2 step = power1 - power2
solution = base ** step solution = base**step
problem = f"The Quotient of ${base}^{{{power1}}}$ and ${base}^{{{power2}}} = " \ problem = f"The Quotient of ${base}^{{{power1}}}$ and ${base}^{{{power2}}} = " \
f"{base}^{{{power1}-{power2}}} = {base}^{{{step}}}$" f"{base}^{{{power1}-{power2}}} = {base}^{{{step}}}$"
@@ -500,7 +501,7 @@ def quotient_of_power_same_power(max_base=50, max_power=10):
base2 = random.randint(1, max_base) base2 = random.randint(1, max_base)
power = random.randint(1, max_power) power = random.randint(1, max_power)
step = base1 / base2 step = base1 / base2
solution = round(step ** power, 2) solution = round(step**power, 2)
problem = f"The quotient of ${base1}^{{{power}}}$ and ${base2}^{{{power}}} = " \ problem = f"The quotient of ${base1}^{{{power}}}$ and ${base2}^{{{power}}} = " \
f"({base1}/{base2})^{power} = {step}^{{{power}}}$" f"({base1}/{base2})^{power} = {step}^{{{power}}}$"
@@ -574,8 +575,7 @@ def surds_comparison(max_value=100, max_root=10):
return problem, f'${solution}$' return problem, f'${solution}$'
def velocity_of_object(max_displacement=1000,max_time=100): def velocity_of_object(max_displacement=1000, max_time=100):
"""Velocity of object """Velocity of object
| Ex. Problem | Ex. Solution | | Ex. Problem | Ex. Solution |
@@ -583,10 +583,9 @@ def velocity_of_object(max_displacement=1000,max_time=100):
| An object travels at uniform velocity a distance of $100 m$ in $4$ seconds. What is the velocity of the car? | $25 m/s$ | | An object travels at uniform velocity a distance of $100 m$ in $4$ seconds. What is the velocity of the car? | $25 m/s$ |
""" """
displacement = random.randint(1, max_displacement)
displacement = random.randint(1,max_displacement)
time_taken = random.randint(1, max_time) time_taken = random.randint(1, max_time)
velocity = "${} m/s$".format(round(displacement/time_taken, 2)) velocity = "${} m/s$".format(round(displacement / time_taken, 2))
problem = f"An object travels at uniform velocity a distance of ${displacement} m$ in ${time_taken}$ seconds. What is the velocity of the car? " problem = f"An object travels at uniform velocity a distance of ${displacement} m$ in ${time_taken}$ seconds. What is the velocity of the car? "
return problem , velocity return problem, velocity

View File

@@ -12,8 +12,8 @@ def combinations(max_lengthgth=20):
a = random.randint(10, max_lengthgth) a = random.randint(10, max_lengthgth)
b = random.randint(0, 9) b = random.randint(0, 9)
solution = int(math.factorial( solution = int(
a) / (math.factorial(b) * math.factorial(a - b))) math.factorial(a) / (math.factorial(b) * math.factorial(a - b)))
problem = f"Find the number of combinations from ${a}$ objects picked ${b}$ at a time." problem = f"Find the number of combinations from ${a}$ objects picked ${b}$ at a time."
return problem, f'${solution}$' return problem, f'${solution}$'
@@ -108,7 +108,7 @@ def data_summary(number_values=15, min_val=5, max_val=50):
var += (random_list[i] - mean)**2 var += (random_list[i] - mean)**2
standardDeviation = round(var / number_values, 2) standardDeviation = round(var / number_values, 2)
variance = round((var / number_values) ** 0.5, 2) variance = round((var / number_values)**0.5, 2)
problem = f"Find the mean,standard deviation and variance for the data ${', '.join(map(str, random_list))}$" problem = f"Find the mean,standard deviation and variance for the data ${', '.join(map(str, random_list))}$"
solution = f"The Mean is ${mean}$, Standard Deviation is ${standardDeviation}$, Variance is ${variance}$" solution = f"The Mean is ${mean}$, Standard Deviation is ${standardDeviation}$, Variance is ${variance}$"

View File

@@ -1,6 +1,7 @@
import os import os
print("You are about to add a new generator to the table in futureGenerators.md") print(
"You are about to add a new generator to the table in futureGenerators.md")
print("Please fill out the following:") print("Please fill out the following:")
title = input("> Title: ") title = input("> Title: ")
example_problem = input("> Example Problem: ") example_problem = input("> Example Problem: ")
@@ -14,4 +15,5 @@ else:
with open(file, 'a') as f: with open(file, 'a') as f:
f.writelines( f.writelines(
f'| {title} | {example_problem} | {example_solution} | {further_explanation} |\n') f'| {title} | {example_problem} | {example_solution} | {further_explanation} |\n'
)

View File

@@ -18,15 +18,17 @@ def get_filepaths(subject_name):
# Join the two strings in order to form the full filepath. # Join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename) filepath = os.path.join(root, filename)
front_len = 24+len(subject_name) front_len = 24 + len(subject_name)
filename = filepath[front_len:-3] filename = filepath[front_len:-3]
file_paths.append(filename) # Add it to the list. file_paths.append(filename) # Add it to the list.
return file_paths return file_paths
subjects = ['algebra', 'basic_math', 'calculus', subjects = [
'computer_science', 'geometry', 'misc', 'statistics'] 'algebra', 'basic_math', 'calculus', 'computer_science', 'geometry',
'misc', 'statistics'
]
for subject in subjects: for subject in subjects:
full_file_paths = get_filepaths(subject) full_file_paths = get_filepaths(subject)
full_file_paths.sort() full_file_paths.sort()

View File

@@ -142,7 +142,7 @@ def main():
for write_line in write_list: for write_line in write_list:
lines.append(write_line) lines.append(write_line)
with open('../README.md', "w", encoding = 'utf-8') as g: with open('../README.md', "w", encoding='utf-8') as g:
g.writelines(lines) g.writelines(lines)
print("New README.md table generated") print("New README.md table generated")

View File

@@ -1,4 +1,4 @@
# Use this file to determine which ID to use for the next generator that you add # Use this file to determine which ID to use for the next generator that you add
from mathgenerator import mathgen from mathgenerator import mathgen
print(mathgen.getGenList()[-1][0]+1) print(mathgen.getGenList()[-1][0] + 1)

View File

@@ -1,7 +1,7 @@
import os import os
name = 'computer_science' name = 'computer_science'
with open (f'/home/luke/src/mathgenerator/mathgenerator/{name}.py', 'w') as f: with open(f'/home/luke/src/mathgenerator/mathgenerator/{name}.py', 'w') as f:
source_dir_path = f'/home/luke/src/mathgenerator/mathgenerator/{name}' source_dir_path = f'/home/luke/src/mathgenerator/mathgenerator/{name}'
files = os.listdir(source_dir_path) files = os.listdir(source_dir_path)
for file in sorted(files): for file in sorted(files):