Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix surface_area_pyramid #443

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions mathgenerator/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,28 @@ def surface_area_pyramid(unit='m'):
(15, 20, 25), (5, 12, 13), (10, 24, 26), (7, 24, 25)]

# Generate first triplet
height, half_width, triangle_height_1 = random.sample(
height, half_width, _ = random.sample(
random.choice(_PYTHAGOREAN), 3)

# Calculate first triangle's area
triangle_1 = half_width * triangle_height_1
# Calculate the first triangle height
triangle_height_1 = math.sqrt((half_width)**2 + height**2)

# Generate second triplet
second_triplet = random.choice([i for i in _PYTHAGOREAN if height in i])
half_length, triangle_height_2 = random.sample(
half_length, _ = random.sample(
tuple(i for i in second_triplet if i != height), 2)

# Calculate second triangle's area
triangle_2 = half_length * triangle_height_2

# Calculate the second triangle height
triangle_height_2 = math.sqrt((half_length)**2 + height**2)

# Calculate triangles area
triangle_1 = half_length * triangle_height_1
triangle_2 = half_width * triangle_height_2

# Calculate base area
base = 4 * half_width * half_length

ans = base + 2 * triangle_1 + 2 * triangle_2

problem = f"Surface area of pyramid with base length $= {2*half_length}{unit}$, base width $= {2*half_width}{unit}$, and height $= {height}{unit}$ is"
solution = f"${ans} {unit}^2$"
return problem, solution
Expand Down
Loading