Skip to content

Add geometric_mean.py #4244

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

Merged
merged 4 commits into from
Mar 1, 2021
Merged

Conversation

ayushbisht2001
Copy link
Contributor

Describe your change:

Added an algorithm to compute the geometric mean of series

  • Add an algorithm

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}.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Feb 28, 2021
"""
if len(series) == 1:
return True
common_ratio = series[1] / series[0]
Copy link
Member

Choose a reason for hiding this comment

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

Will fail with empty series.

Copy link
Member

Choose a reason for hiding this comment

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

Also if series[0] is 0 will fail as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fail with empty series.

for that I have check the size of list. If it is zero then It will raise an error.

if len(series) == 0:
     raise ValueError("Input list must be a non empty list")

Would it be fine or ... how can I do it in a better way ?

Copy link
Member

Choose a reason for hiding this comment

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

Right, didn't notice.

raise ValueError("Input list is not a geometric series")
answer = 1
for _ in series:
answer *= _
Copy link
Member

Choose a reason for hiding this comment

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

I don't like it named _. _ means that it's not important but actually it's affecting answer variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like it named _. _ means that it's not important but actually it's affecting answer variable.

sorry for this silly mistake.

@@ -0,0 +1,55 @@
def is_geometric_series(series: list) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Please add link with some theory about algorithm.

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Mar 1, 2021
@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Mar 1, 2021
@ayushbisht2001
Copy link
Contributor Author

@mateuszz0000 , I tried to resolve all the mistakes. I know you all guys are also busy, so if you get some time, then please review this PR .
Thank you.. for all your kind suggestions and responses.

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Mar 1, 2021
@l3str4nge l3str4nge merged commit 0435128 into TheAlgorithms:master Mar 1, 2021
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
* geometric_mean3

* update-GM.PY

* update-AM.PY

* Revert "update-AM.PY"

This reverts commit 11792ec.
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* geometric_mean3

* update-GM.PY

* update-AM.PY

* Revert "update-AM.PY"

This reverts commit 11792ec.
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* geometric_mean3

* update-GM.PY

* update-AM.PY

* Revert "update-AM.PY"

This reverts commit 11792ec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants