Skip to content

Included area of n sided regular polygon#7438

Merged
cclauss merged 4 commits intoTheAlgorithms:masterfrom
mislah:patch-4
Oct 25, 2022
Merged

Included area of n sided regular polygon#7438
cclauss merged 4 commits intoTheAlgorithms:masterfrom
mislah:patch-4

Conversation

@mislah
Copy link
Copy Markdown
Contributor

@mislah mislah commented Oct 20, 2022

Added a function to calculate the area of n sided regular polygons

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Added a function to calculate the area of n sided regular polygons
@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 20, 2022
@@ -458,6 +458,49 @@ def area_rhombus(diagonal_1: float, diagonal_2: float) -> float:
return 1 / 2 * diagonal_1 * diagonal_2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add some doctests here too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! doctests were already present in there. I wonder if that's a mistake.

Comment on lines 524 to +529
print(f"Cone: {surface_area_cone(10, 20) = }")
print(f"Conical Frustum: {surface_area_conical_frustum(10, 20, 30) = }")
print(f"Cylinder: {surface_area_cylinder(10, 20) = }")
print(f"Equilateral Triangle: {area_reg_polygon(3, 10) = }")
print(f"Square: {area_reg_polygon(4, 10) = }")
print(f"Reqular Pentagon: {area_reg_polygon(5, 10) = }")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need them since you already used doctest to test your code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ZeroDayOwl , Based on the format of preexisting functions, I doubt if I'm allowed to proceed with your suggestion.

"area_reg_polygon() only accepts non-negative values as \
length of a side"
)
return (sides * length**2) / (4 * tan(pi / sides))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (sides * length**2) / (4 * tan(pi / sides))
return (sides * pow(length, 2)) / (4 * tan(pi / sides))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @CaedenPH , Based on the format of preexisting functions, I doubt if I'm allowed to commit your suggestion.

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 25, 2022
@cclauss cclauss merged commit 505c5e2 into TheAlgorithms:master Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants