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