1import random
+ 2import math
+ 3from math import cos, sin, pi
+ 4
+ 5
+ 6def angle_btw_vectors(max_elt_amt=20):
+ 7 r"""Angle between 2 vectors
+ 8
+ 9 | Ex. Problem | Ex. Solution |
+ 10 | --- | --- |
+ 11 | angle between the vectors $[363.84, 195.54, 997.08, 39.26, 60.14, 722.7, 888.57, 713.15, 436.22, 712.23, 349.23, 595.91, 191.8, 824.58, 861.56, 122.73, 815.14, 700.68, 506.5]$ and $[760.85, 934.67, 513.37, 796.93, 809.97, 423.54, 162.69, 758.96, 133.42, 478.14, 771.84, 824.88, 483.07, 134.41, 954.41, 893.42, 191.01, 453.97, 648.59]$ is: | $0.81$ radians |
+ 12 """
+ 13 s = 0
+ 14 v1 = [
+ 15 round(random.uniform(0, 1000), 2)
+ 16 for i in range(random.randint(2, max_elt_amt))
+ 17 ]
+ 18 v2 = [round(random.uniform(0, 1000), 2) for i in v1]
+ 19 for i in range(len(v1)):
+ 20 s += v1[i] * v2[i]
+ 21
+ 22 mags = math.sqrt(sum([i**2
+ 23 for i in v1])) * math.sqrt(sum([i**2 for i in v2]))
+ 24 solution = ''
+ 25 ans = 0
+ 26 try:
+ 27 ans = round(math.acos(s / mags), 2)
+ 28 solution = f"${ans}$ radians"
+ 29 except ValueError:
+ 30 print('angleBtwVectorsFunc has some issues with math module, line 16')
+ 31 solution = 'NaN'
+ 32 ans = 'NaN'
+ 33 # would return the answer in radians
+ 34 problem = f"angle between the vectors ${v1}$ and ${v2}$ is:"
+ 35 return problem, solution
+ 36
+ 37
+ 38def angle_regular_polygon(min_val=3, max_val=20):
+ 39 r"""Angle of a Regular Polygon
+ 40
+ 41 | Ex. Problem | Ex. Solution |
+ 42 | --- | --- |
+ 43 | Find the angle of a regular polygon with $8$ sides | $135.0$ |
+ 44 """
+ 45 sideNum = random.randint(min_val, max_val)
+ 46 problem = f"Find the angle of a regular polygon with ${sideNum}$ sides"
+ 47
+ 48 exteriorAngle = round((360 / sideNum), 2)
+ 49 solution = f'${180 - exteriorAngle}$'
+ 50
+ 51 return problem, solution
+ 52
+ 53
+ 54def arc_length(max_radius=49, max_angle=359):
+ 55 r"""Arc length of Angle
+ 56
+ 57 | Ex. Problem | Ex. Solution |
+ 58 | --- | --- |
+ 59 | Given radius, $44$ and angle, $184$. Find the arc length of the angle. | Arc length of the angle $= 141.30186$ |
+ 60 """
+ 61 radius = random.randint(1, max_radius)
+ 62 angle = random.randint(1, max_angle)
+ 63 angle_arc_length = float((angle / 360) * 2 * math.pi * radius)
+ 64 formatted_float = "{:.5f}".format(angle_arc_length)
+ 65
+ 66 problem = f"Given radius, ${radius}$ and angle, ${angle}$. Find the arc length of the angle."
+ 67 solution = f"Arc length of the angle $= {formatted_float}$"
+ 68 return problem, solution
+ 69
+ 70
+ 71def area_of_circle(max_radius=100):
+ 72 r"""Area of Circle
+ 73
+ 74 | Ex. Problem | Ex. Solution |
+ 75 | --- | --- |
+ 76 | Area of circle with radius $29=$ | $2642.08$ |
+ 77 """
+ 78 r = random.randint(0, max_radius)
+ 79 area = round(pi * r * r, 2)
+ 80
+ 81 problem = f'Area of circle with radius ${r}=$'
+ 82 return problem, f'${area}$'
+ 83
+ 84
+ 85def area_of_circle_given_center_and_point(max_coordinate=10, max_radius=10):
+ 86 r"""Area of Circle given center and a point on circle
+ 87
+ 88 | Ex. Problem | Ex. Solution |
+ 89 | --- | --- |
+ 90 | Area of circle with center $(7,-6)$ and passing through $(1.0, -6.0)$ is | $113.1$ |
+ 91 """
+ 92 r = random.randint(0, max_radius)
+ 93 center_x = random.randint(-max_coordinate, max_coordinate)
+ 94 center_y = random.randint(-max_coordinate, max_coordinate)
+ 95
+ 96 angle = random.choice([0, pi // 6, pi // 2, pi, pi + pi // 6, 3 * pi // 2])
+ 97
+ 98 point_x = center_x + round(r * cos(angle), 2)
+ 99 point_y = center_y + round(r * sin(angle), 2)
+100
+101 area = round(pi * r * r, 2)
+102
+103 problem = f"Area of circle with center $({center_x},{center_y})$ and passing through $({point_x}, {point_y})$ is"
+104 return problem, f'${area}$'
+105
+106
+107def area_of_triangle(max_a=20, max_b=20):
+108 r"""Area of Triangle
+109
+110 | Ex. Problem | Ex. Solution |
+111 | --- | --- |
+112 | Area of triangle with side lengths: $8, 1, 8 = $ | $3.99$ |
+113 """
+114 a = random.randint(1, max_a)
+115 b = random.randint(1, max_b)
+116 c = random.randint(abs(b - a) + 1, abs(a + b) - 1)
+117
+118 s = (a + b + c) / 2
+119 area = (s * (s - a) * (s - b) * (s - c))**0.5
+120
+121 problem = f"Area of triangle with side lengths: ${a}, {b}, {c} = $"
+122 solution = f'${round(area, 2)}$'
+123 return problem, solution
+124
+125
+126# Handles degrees in quadrant one
+127def basic_trigonometry(angles=[0, 30, 45, 60, 90],
+128 functions=["sin", "cos", "tan"]):
+129 r"""Trigonometric Values
+130
+131 | Ex. Problem | Ex. Solution |
+132 | --- | --- |
+133 | $\sin(30) = $ | $\frac{1}{2}$ |
+134 """
+135 angle = random.choice(angles)
+136 function = random.choice(functions)
+137
+138 problem = rf"$\{function}({angle}) = $"
+139
+140 expression = 'math.' + function + '(math.radians(angle))'
+141 result_fraction_map = {
+142 0.0: "0",
+143 0.5: r"\frac{1}{2}",
+144 0.71: r"\frac{1}{\sqrt{2}}",
+145 0.87: r"\frac{\sqrt{3}}{2}",
+146 1.0: "1",
+147 0.58: r"\frac{1}{\sqrt{3}}",
+148 1.73: r"\sqrt{3}",
+149 }
+150
+151 solution = result_fraction_map[round(eval(expression), 2)] if round(
+152 eval(expression), 2) <= 99999 else r"\infty" # for handling the ∞ condition
+153
+154 return problem, f'${solution}$'
+155
+156
+157def circumference(max_radius=100):
+158 r"""Circumference of Circle
+159
+160 | Ex. Problem | Ex. Solution |
+161 | --- | --- |
+162 | Circumference of circle with radius $56 = $ | $351.86$ |
+163 """
+164 r = random.randint(0, max_radius)
+165 circumference = round(2 * math.pi * r, 2)
+166
+167 problem = f"Circumference of circle with radius ${r} = $"
+168 return problem, f'${circumference}$'
+169
+170
+171def complementary_and_supplementary_angle(max_supp=180, max_comp=90):
+172 r"""Complementary and Supplementary Angle
+173
+174 | Ex. Problem | Ex. Solution |
+175 | --- | --- |
+176 | The complementary angle of $15 =$ | $75$ |
+177 """
+178 angleType = random.choice(["supplementary", "complementary"])
+179
+180 if angleType == "supplementary":
+181 angle = random.randint(1, max_supp)
+182 angleAns = 180 - angle
+183 else:
+184 angle = random.randint(1, max_comp)
+185 angleAns = 90 - angle
+186
+187 problem = f"The {angleType} angle of ${angle} =$"
+188 solution = f'${angleAns}$'
+189 return problem, solution
+190
+191
+192def curved_surface_area_cylinder(max_radius=49, max_height=99):
+193 r"""Curved surface area of a cylinder
+194
+195 | Ex. Problem | Ex. Solution |
+196 | --- | --- |
+197 | What is the curved surface area of a cylinder of radius, $44$ and height, $92$? | $25434.33$ |
+198 """
+199 r = random.randint(1, max_radius)
+200 h = random.randint(1, max_height)
+201 csa = float(2 * math.pi * r * h)
+202 formatted_float = round(csa, 2) # "{:.5f}".format(csa)
+203
+204 problem = f"What is the curved surface area of a cylinder of radius, ${r}$ and height, ${h}$?"
+205 solution = f"${formatted_float}$"
+206 return problem, solution
+207
+208
+209def degree_to_rad(max_deg=360):
+210 r"""Degrees to Radians
+211
+212 | Ex. Problem | Ex. Solution |
+213 | --- | --- |
+214 | Angle $113$ degrees in radians is: | $1.97$ |
+215 """
+216 a = random.randint(0, max_deg)
+217 b = (math.pi * a) / 180
+218 b = round(b, 2)
+219
+220 problem = f"Angle ${a}$ degrees in radians is: "
+221 solution = f'${b}$'
+222 return problem, solution
+223
+224
+225def equation_of_line_from_two_points(max_coordinate=20, min_coordinate=-20):
+226 r"""Equation of line from two points
+227
+228 | Ex. Problem | Ex. Solution |
+229 | --- | --- |
+230 | What is the equation of the line between points $(13,9)$ and $(6,-19)$ in slope-intercept form? | $y = 4x -43$ |
+231 """
+232 x1 = random.randint(min_coordinate, max_coordinate)
+233 x2 = random.randint(min_coordinate, max_coordinate)
+234
+235 y1 = random.randint(min_coordinate, max_coordinate)
+236 y2 = random.randint(min_coordinate, max_coordinate)
+237
+238 coeff_y = (x2 - x1)
+239 coeff_x = (y2 - y1)
+240 constant = y2 * coeff_y - x2 * coeff_x
+241
+242 gcd = math.gcd(abs(coeff_x), abs(coeff_y))
+243
+244 if gcd != 1:
+245 if coeff_y > 0:
+246 coeff_y //= gcd
+247 if coeff_x > 0:
+248 coeff_x //= gcd
+249 if constant > 0:
+250 constant //= gcd
+251 if coeff_y < 0:
+252 coeff_y = -(-coeff_y // gcd)
+253 if coeff_x < 0:
+254 coeff_x = -(-coeff_x // gcd)
+255 if constant < 0:
+256 constant = -(-constant // gcd)
+257 if coeff_y < 0:
+258 coeff_y = -(coeff_y)
+259 coeff_x = -(coeff_x)
+260 constant = -(constant)
+261 if coeff_x in [1, -1]:
+262 if coeff_x == 1:
+263 coeff_x = ''
+264 else:
+265 coeff_x = '-'
+266 if coeff_y in [1, -1]:
+267 if coeff_y == 1:
+268 coeff_y = ''
+269 else:
+270 coeff_y = '-'
+271
+272 problem = f"What is the equation of the line between points $({x1},{y1})$ and $({x2},{y2})$ in slope-intercept form?"
+273 if coeff_x == 0:
+274 solution = str(coeff_y) + "y = " + str(constant)
+275 elif coeff_y == 0:
+276 solution = str(coeff_x) + "x = " + str(-constant)
+277 else:
+278 if constant > 0:
+279 solution = str(coeff_y) + "y = " + str(coeff_x) + \
+280 "x + " + str(constant)
+281 else:
+282 solution = str(coeff_y) + "y = " + \
+283 str(coeff_x) + "x " + str(constant)
+284 return problem, f'${solution}$'
+285
+286
+287def fourth_angle_of_quadrilateral(max_angle=180):
+288 r"""Fourth Angle of Quadrilateral
+289
+290 | Ex. Problem | Ex. Solution |
+291 | --- | --- |
+292 | Fourth angle of quadrilateral with angles $162 , 43, 78 =$ | $77$ |
+293 """
+294 angle1 = random.randint(1, max_angle)
+295 angle2 = random.randint(1, 240 - angle1)
+296 angle3 = random.randint(1, 340 - (angle1 + angle2))
+297
+298 sum_ = angle1 + angle2 + angle3
+299 angle4 = 360 - sum_
+300
+301 problem = f"Fourth angle of quadrilateral with angles ${angle1} , {angle2}, {angle3} =$"
+302 solution = f'${angle4}$'
+303 return problem, solution
+304
+305
+306def perimeter_of_polygons(max_sides=12, max_length=120):
+307 r"""Perimeter of Polygons
+308
+309 | Ex. Problem | Ex. Solution |
+310 | --- | --- |
+311 | The perimeter of a $4$ sided polygon with lengths of $30, 105, 78, 106$cm is: | $319$ |
+312 """
+313 size_of_sides = random.randint(3, max_sides)
+314 sides = [random.randint(1, max_length) for _ in range(size_of_sides)]
+315
+316 problem = f"The perimeter of a ${size_of_sides}$ sided polygon with lengths of ${', '.join(map(str, sides))}$cm is: "
+317 solution = sum(sides)
+318
+319 return problem, f'${solution}$'
+320
+321
+322def pythagorean_theorem(max_length=20):
+323 """Pythagorean Theorem
+324
+325 | Ex. Problem | Ex. Solution |
+326 | --- | --- |
+327 | What is the hypotenuse of a right triangle given the other two sides have lengths $9$ and $10$? | $13.45$ |
+328 """
+329 a = random.randint(1, max_length)
+330 b = random.randint(1, max_length)
+331 c = round((a ** 2 + b ** 2) ** 0.5, 2)
+332
+333 problem = f"What is the hypotenuse of a right triangle given the other two sides have lengths ${a}$ and ${b}$?"
+334 solution = f"${c}$"
+335 return problem, solution
+336
+337
+338def radian_to_deg(max_rad=6.28):
+339 """Radians to Degrees"""
+340 a = random.randint(0, int(max_rad * 100)) / 100
+341 b = round((180 * a) / math.pi, 2)
+342
+343 problem = f"Angle ${a}$ radians in degrees is: "
+344 solution = f'${b}$'
+345 return problem, solution
+346
+347
+348def sector_area(max_radius=49, max_angle=359):
+349 """Area of a Sector
+350
+351 | Ex. Problem | Ex. Solution |
+352 | --- | --- |
+353 | What is the area of a sector with radius $42$ and angle $83$ degrees? | $1277.69$ |
+354 """
+355 r = random.randint(1, max_radius)
+356 a = random.randint(1, max_angle)
+357 secArea = float((a / 360) * math.pi * r * r)
+358 formatted_float = round(secArea, 2)
+359
+360 problem = f"What is the area of a sector with radius ${r}$ and angle ${a}$ degrees?"
+361 solution = f"${formatted_float}$"
+362 return problem, solution
+363
+364
+365def sum_of_polygon_angles(max_sides=12):
+366 """Sum of Angles of Polygon
+367
+368 | Ex. Problem | Ex. Solution |
+369 | --- | --- |
+370 | What is the sum of interior angles of a polygon with $8$ sides? | $1080$ |
+371 """
+372 side_count = random.randint(3, max_sides)
+373 sum = (side_count - 2) * 180
+374
+375 problem = f"What is the sum of interior angles of a polygon with ${side_count}$ sides?"
+376 return problem, f'${sum}$'
+377
+378
+379def surface_area_cone(max_radius=20, max_height=50, unit='m'):
+380 """Surface area of a cone
+381
+382 | Ex. Problem | Ex. Solution |
+383 | --- | --- |
+384 | Surface area of cone with height $= 26m$ and radius $= 6m$ is | $616 m^2$ |
+385 """
+386 a = random.randint(1, max_height)
+387 b = random.randint(1, max_radius)
+388
+389 slopingHeight = math.sqrt(a**2 + b**2)
+390 ans = int(math.pi * b * slopingHeight + math.pi * b * b)
+391
+392 problem = f"Surface area of cone with height $= {a}{unit}$ and radius $= {b}{unit}$ is"
+393 solution = f"${ans} {unit}^2$"
+394 return problem, solution
+395
+396
+397def surface_area_cube(max_side=20, unit='m'):
+398 """Surface area of a cube
+399
+400 | Ex. Problem | Ex. Solution |
+401 | --- | --- |
+402 | Surface area of cube with side $= 6m$ is | $216 m^2$ |
+403 """
+404 a = random.randint(1, max_side)
+405 ans = 6 * (a ** 2)
+406
+407 problem = f"Surface area of cube with side $= {a}{unit}$ is"
+408 solution = f"${ans} {unit}^2$"
+409 return problem, solution
+410
+411
+412def surface_area_cuboid(max_side=20, unit='m'):
+413 """Surface area of a cuboid
+414
+415 | Ex. Problem | Ex. Solution |
+416 | --- | --- |
+417 | Surface area of cuboid with sides of lengths: $11m, 20m, 8m$ is | $936 m^2$ |
+418 """
+419 a = random.randint(1, max_side)
+420 b = random.randint(1, max_side)
+421 c = random.randint(1, max_side)
+422 ans = 2 * (a * b + b * c + c * a)
+423
+424 problem = f"Surface area of cuboid with sides of lengths: ${a}{unit}, {b}{unit}, {c}{unit}$ is"
+425 solution = f"${ans} {unit}^2$"
+426 return problem, solution
+427
+428
+429def surface_area_cylinder(max_radius=20, max_height=50, unit='m'):
+430 """Surface area of a cylinder
+431
+432 | Ex. Problem | Ex. Solution |
+433 | --- | --- |
+434 | Surface area of cylinder with height $= 26m$ and radius $= 15m$ is | $3864 m^2$ |
+435 """
+436 a = random.randint(1, max_height)
+437 b = random.randint(1, max_radius)
+438 ans = int(2 * math.pi * a * b + 2 * math.pi * b * b)
+439
+440 problem = f"Surface area of cylinder with height $= {a}{unit}$ and radius $= {b}{unit}$ is"
+441 solution = f"${ans} {unit}^2$"
+442 return problem, solution
+443
+444
+445def surface_area_pyramid(unit='m'):
+446 """Surface area of a pyramid
+447
+448 | Ex. Problem | Ex. Solution |
+449 | --- | --- |
+450 | Surface area of pyramid with base length $= 30m$, base width $= 40m$, and height $= 25m$ is | $2400 m^2$ |
+451 """
+452 # List of Pythagorean triplets
+453 _PYTHAGOREAN = [(3, 4, 5),
+454 (6, 8, 10),
+455 (9, 12, 15),
+456 (12, 16, 20),
+457 (15, 20, 25),
+458 (5, 12, 13),
+459 (10, 24, 26),
+460 (7, 24, 25)]
+461
+462 # Generate first triplet
+463 height, half_width, triangle_height_1 = random.sample(
+464 random.choice(_PYTHAGOREAN), 3)
+465
+466 # Calculate first triangle's area
+467 triangle_1 = half_width * triangle_height_1
+468
+469 # Generate second triplet
+470 second_triplet = random.choice([i for i in _PYTHAGOREAN if height in i])
+471 half_length, triangle_height_2 = random.sample(
+472 tuple(i for i in second_triplet if i != height), 2)
+473
+474 # Calculate second triangle's area
+475 triangle_2 = half_length * triangle_height_2
+476
+477 # Calculate base area
+478 base = 4 * half_width * half_length
+479
+480 ans = base + 2 * triangle_1 + 2 * triangle_2
+481
+482 problem = f"Surface area of pyramid with base length $= {2*half_length}{unit}$, base width $= {2*half_width}{unit}$, and height $= {height}{unit}$ is"
+483 solution = f"${ans} {unit}^2$"
+484 return problem, solution
+485
+486
+487def surface_area_sphere(max_side=20, unit='m'):
+488 """Surface area of a sphere
+489
+490 | Ex. Problem | Ex. Solution |
+491 | --- | --- |
+492 | Surface area of a sphere with radius $= 8m$ is | $804.25 m^2$ |
+493 """
+494 r = random.randint(1, max_side)
+495 ans = round(4 * math.pi * r * r, 2)
+496
+497 problem = f"Surface area of a sphere with radius $= {r}{unit}$ is"
+498 solution = f"${ans} {unit}^2$"
+499 return problem, solution
+500
+501
+502def third_angle_of_triangle(max_angle=89):
+503 """Third Angle of Triangle
+504
+505 | Ex. Problem | Ex. Solution |
+506 | --- | --- |
+507 | Third angle of triangle with angles $10$ and $22 =$ | $148$ |
+508 """
+509 angle1 = random.randint(1, max_angle)
+510 angle2 = random.randint(1, max_angle)
+511 angle3 = 180 - (angle1 + angle2)
+512
+513 problem = f"Third angle of triangle with angles ${angle1}$ and ${angle2} = $"
+514 return problem, f'${angle3}$'
+515
+516
+517def valid_triangle(max_side_length=50):
+518 """Valid Triangle
+519
+520 | Ex. Problem | Ex. Solution |
+521 | --- | --- |
+522 | Does triangel with sides $10, 31$ and $14$ exist? | No |
+523 """
+524 sideA = random.randint(1, max_side_length)
+525 sideB = random.randint(1, max_side_length)
+526 sideC = random.randint(1, max_side_length)
+527
+528 sideSums = [sideA + sideB, sideB + sideC, sideC + sideA]
+529 sides = [sideC, sideA, sideB]
+530
+531 exists = True & (sides[0] < sideSums[0]) & (sides[1] < sideSums[1]) & (
+532 sides[2] < sideSums[2])
+533
+534 problem = f"Does triangle with sides ${sideA}, {sideB}$ and ${sideC}$ exist?"
+535 solution = "Yes" if exists else "No"
+536 return problem, f'${solution}$'
+537
+538
+539def volume_cone(max_radius=20, max_height=50, unit='m'):
+540 """Volume of a cone
+541
+542 | Ex. Problem | Ex. Solution |
+543 | --- | --- |
+544 | Volume of cone with height $= 44m$ and radius $= 11m$ is | $5575 m^3$ |
+545 """
+546 a = random.randint(1, max_height)
+547 b = random.randint(1, max_radius)
+548 ans = int(math.pi * b * b * a * (1 / 3))
+549
+550 problem = f"Volume of cone with height $= {a}{unit}$ and radius $= {b}{unit}$ is"
+551 solution = f"${ans} {unit}^3$"
+552 return problem, solution
+553
+554
+555def volume_cube(max_side=20, unit='m'):
+556 """Volume of a cube
+557 | Ex. Problem | Ex. Solution |
+558 | --- | --- |
+559 | Volume of a cube with a side length of $19m$ is | $6859 m^3$ |
+560 """
+561 a = random.randint(1, max_side)
+562 ans = a**3
+563
+564 problem = f"Volume of cube with a side length of ${a}{unit}$ is"
+565 solution = f"${ans} {unit}^3$"
+566 return problem, solution
+567
+568
+569def volume_cuboid(max_side=20, unit='m'):
+570 """Volume of a cuboid
+571
+572 | Ex. Problem | Ex. Solution |
+573 | --- | --- |
+574 | Volume of cuboid with sides = $17m, 11m, 13m$ is | $2431 m^3$ |
+575 """
+576 a = random.randint(1, max_side)
+577 b = random.randint(1, max_side)
+578 c = random.randint(1, max_side)
+579 ans = a * b * c
+580
+581 problem = f"Volume of cuboid with sides = ${a}{unit}, {b}{unit}, {c}{unit}$ is"
+582 solution = f"${ans} {unit}^3$"
+583 return problem, solution
+584
+585
+586def volume_cylinder(max_radius=20, max_height=50, unit='m'):
+587 """Volume of a cylinder
+588
+589 | Ex. Problem | Ex. Solution |
+590 | --- | --- |
+591 | Volume of cylinder with height $= 3m$ and radius $= 10m$ is | $942 m^3$ |
+592 """
+593 a = random.randint(1, max_height)
+594 b = random.randint(1, max_radius)
+595 ans = int(math.pi * b * b * a)
+596
+597 problem = f"Volume of cylinder with height $= {a}{unit}$ and radius $= {b}{unit}$ is"
+598 solution = f"${ans} {unit}^3$"
+599 return problem, solution
+600
+601
+602def volume_cone_frustum(max_r1=20, max_r2=20, max_height=50, unit='m'):
+603 """Volume of the frustum of a cone
+604
+605 | Ex. Problem | Ex. Solution |
+606 | --- | --- |
+607 | Volume of frustum with height $= 30m$ and $r1 = 20m$ is and $r2 = 8m$ is | $19603.54 m^3$ |
+608 """
+609 h = random.randint(1, max_height)
+610 r1 = random.randint(1, max_r1)
+611 r2 = random.randint(1, max_r2)
+612 ans = round(((math.pi * h) * (r1 ** 2 + r2 ** 2 + r1 * r2)) / 3, 2)
+613
+614 problem = f"Volume of frustum with height $= {h}{unit}$ and $r1 = {r1}{unit}$ is and $r2 = {r2}{unit}$ is "
+615 solution = f"${ans} {unit}^3$"
+616 return problem, solution
+617
+618
+619def volume_hemisphere(max_radius=100):
+620 """Volume of a hemisphere
+621
+622 | Ex. Problem | Ex. Solution |
+623 | --- | --- |
+624 | Volume of hemisphere with radius $32m =$ | $68629.14 m^3$ |
+625 """
+626 r = random.randint(1, max_radius)
+627 ans = round((2 * math.pi / 3) * r**3, 2)
+628
+629 problem = f"Volume of hemisphere with radius ${r} m =$ "
+630 solution = f"${ans} m^3$"
+631 return problem, solution
+632
+633
+634def volume_pyramid(max_length=20, max_width=20, max_height=50, unit='m'):
+635 """Volume of a pyramid
+636
+637 | Ex. Problem | Ex. Solution |
+638 | --- | --- |
+639 | Volume of pyramid with base length $= 7 m$, base width $= 18 m$ and height $= 42 m$ is | $1764.0 m^3$ |
+640 """
+641 length = random.randint(1, max_length)
+642 width = random.randint(1, max_width)
+643 height = random.randint(1, max_height)
+644
+645 ans = round((length * width * height) / 3, 2)
+646
+647 problem = f"Volume of pyramid with base length $= {length} {unit}$, base width $= {width} {unit}$ and height $= {height} {unit}$ is"
+648 solution = f"${ans} {unit}^3$"
+649 return problem, solution
+650
+651
+652def volume_sphere(max_radius=100):
+653 """Volume of a sphere
+654
+655 | Ex. Problem | Ex. Solution |
+656 | --- | --- |
+657 | Volume of sphere with radius $30 m = $ | $113097.36 m^3$ |
+658 """
+659 r = random.randint(1, max_radius)
+660 ans = round((4 * math.pi / 3) * r**3, 2)
+661
+662 problem = f"Volume of sphere with radius ${r} m = $"
+663 solution = f"${ans} m^3$"
+664 return problem, solution
+
+
+
+