Merge branch 'master' into master

This commit is contained in:
Luke Weiler
2020-10-23 13:35:30 -04:00
committed by GitHub
12 changed files with 325 additions and 127 deletions

View File

@@ -100,4 +100,10 @@ from .complex_to_polar import *
from .set_operation import *
from .base_conversion import *
from .curved_surface_area_cylinder import *
from .minutesToHours import *
from .perimeter_of_polygons import *
from .power_of_powers import *
from .quotient_of_power_same_base import *
from .quotient_of_power_same_power import *
from .complex_quadratic import *
from .is_leap_year import *
from .minutesToHours import *

View File

@@ -4,18 +4,20 @@ import math
def angleBtwVectorsFunc(maxEltAmt=20):
s = 0
v1 = [random.uniform(0, 1000) for i in range(random.randint(2, maxEltAmt))]
v2 = [random.uniform(0, 1000) for i in v1]
for i in v1:
for j in v2:
s += i * j
v1 = [
round(random.uniform(0, 1000), 2)
for i in range(random.randint(2, maxEltAmt))
]
v2 = [round(random.uniform(0, 1000), 2) for i in v1]
for i in range(len(v1)):
s += v1[i] * v2[i]
mags = math.sqrt(sum([i**2
for i in v1])) * math.sqrt(sum([i**2 for i in v2]))
problem = f"angle between the vectors {v1} and {v2} is:"
solution = ''
try:
solution = str(math.acos(s / mags))
solution = str(round(math.acos(s / mags), 2)) + " radians"
except ValueError:
print('angleBtwVectorsFunc has some issues with math module, line 16')
solution = 'NaN'

View File

@@ -0,0 +1,75 @@
from .__init__ import *
def complexQuadraticFunc(prob_type=0, max_range=10):
if prob_type < 0 or prob_type > 1:
print("prob_type not supported")
print("prob_type = 0 for real roots problems ")
print("prob_tpye = 1 for imaginary roots problems")
return None
if prob_type == 0:
d = -1
while d < 0:
a = random.randrange(1, max_range)
b = random.randrange(1, max_range)
c = random.randrange(1, max_range)
d = (b**2 - 4 * a * c)
else:
d = 0
while d >= 0:
a = random.randrange(1, max_range)
b = random.randrange(1, max_range)
c = random.randrange(1, max_range)
d = (b**2 - 4 * a * c)
eq = ''
if a == 1:
eq += 'x^2 + '
else:
eq += str(a) + 'x^2 + '
if b == 1:
eq += 'x + '
else:
eq += str(b) + 'x + '
eq += str(c) + ' = 0'
problem = 'Find the roots of given Quadratic Equation ' + eq
if d < 0:
sqrt_d = (-d)**0.5
if sqrt_d - int(sqrt_d) == 0:
sqrt_d = int(sqrt_d)
solution = f'(({-b} + {sqrt_d}i)/2*{a}, ({-b} - {sqrt_d}i)/2*{a})'
else:
solution = f'(({-b} + sqrt({-d})i)/2*{a}, ({-b} - sqrt({-d})i)/2*{a})'
return problem, solution
else:
s_root1 = round((-b + (d)**0.5) / (2 * a), 3)
s_root2 = round((-b - (d)**0.5) / (2 * a), 3)
sqrt_d = (d)**0.5
if sqrt_d - int(sqrt_d) == 0:
sqrt_d = int(sqrt_d)
g_sol = f'(({-b} + {sqrt_d})/2*{a}, ({-b} - {sqrt_d})/2*{a})'
else:
g_sol = f'(({-b} + sqrt({d}))/2*{a}, ({-b} - sqrt({d}))/2*{a})'
solution = f'simplified solution : ({s_root1, s_root2}), generalized solution : ' + g_sol
return problem, solution
complex_quadratic = Generator(
"complex Quadratic Equation", 100,
"Find the roots of given Quadratic Equation ",
"simplified solution : (x1, x2), generalized solution : ((-b + sqrt(d))/2a, (-b - sqrt(d))/2a) or ((-b + sqrt(d)i)/2a, (-b - sqrt(d)i)/2a)",
complexQuadraticFunc)

View File

@@ -0,0 +1,25 @@
from .__init__ import *
def IsLeapYear(minNumber=1900, maxNumber=2099):
year = random.randint(minNumber, maxNumber)
problem = "Year " + str(year) + " "
solution = ""
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
solution = "is a leap year"
else:
solution = "is not a leap year"
else:
solution = "is a leap year"
else:
solution = "is not a leap year"
return problem, solution
is_leap_year = Generator("Leap Year or Not", 101,
"Year y ", "is/not a leap year",
IsLeapYear)
# for readme ## | 102 | Leap Year or Not | Year 1964 | is a leap year | is_leap_year |

View File

@@ -0,0 +1,20 @@
from .__init__ import *
def perimeterOfPolygons(maxSides=12, maxLength=120):
size_of_sides = random.randint(3, maxSides)
sides = []
for x in range(size_of_sides):
sides.append(random.randint(1, maxLength))
problem = "The perimeter of a " + str(size_of_sides) + \
" sided polygon with lengths of " + str(sides) + "cm is: "
solution = 0
for y in range(len(sides)):
solution += sides[y]
return problem, solution
perimeter_of_polygons = Generator(
"Perimeter of Polygons", 96,
"The perimeter of a x sided polygon with lengths of y cm is: ", "z",
perimeterOfPolygons)

View File

@@ -0,0 +1,20 @@
from .__init__ import *
def powerOfPowersFunc(maxBase=50, maxPower=10):
base = random.randint(1, maxBase)
power1 = random.randint(1, maxPower)
power2 = random.randint(1, maxPower)
step = power1 * power2
problem = "The {base}^{power1}^{power2} = " \
"{base}^({power1}*{power2}) = {base}^{step}".format(base=base,
power1=power1,
power2=power2,
step=step)
solution = str(base**step)
return problem, solution
power_of_powers = Generator("Power of Powers", 97, "6^4^2 = 6^(4*2) = 6^6",
"46656", powerOfPowersFunc)

View File

@@ -0,0 +1,21 @@
from .__init__ import *
def quotientOfPowerSameBaseFunc(maxBase=50, maxPower=10):
base = random.randint(1, maxBase)
power1 = random.randint(1, maxPower)
power2 = random.randint(1, maxPower)
step = power1 - power2
problem = "The Quotient of {base}^{power1} and {base}^{power2} = " \
"{base}^({power1}-{power2}) = {base}^{step}".format(base=base,
power1=power1,
power2=power2,
step=step)
solution = str(base**step)
return problem, solution
quotient_of_power_same_base = Generator("Quotient of Powers with Same Base",
98, "6^4 / 6^2 = 6^(4-2) = 6^2", "36",
quotientOfPowerSameBaseFunc)

View File

@@ -0,0 +1,21 @@
from .__init__ import *
def quotientOfPowerSamePowerFunc(maxBase=50, maxPower=10):
base1 = random.randint(1, maxBase)
base2 = random.randint(1, maxBase)
power = random.randint(1, maxPower)
step = base1 / base2
problem = "The Quotient of {base1}^{power} and {base2}^{power} = " \
"({base1}/{base2})^{power} = {step}^{power}".format(base1=base1,
base2=base2,
power=power,
step=step)
solution = str(step**power)
return problem, solution
quotient_of_power_same_power = Generator("Quotient of Powers with Same Power",
99, "6^4 / 3^4 = (6/3)^4 = 2^4", "16",
quotientOfPowerSamePowerFunc)