-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
maths-polynomial_evalutation #1214
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
Conversation
maths/polynomial_evaluation.py
Outdated
""" | ||
i = 0 | ||
res = 0 | ||
for c in poly: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i, c in enumerate(poly): # then delete lines 14 and 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the whole function can be a one-liner: return sum(c * x ** i for i, c in enumerate(poly))
poly: tuple of numbers - value of cofficients | ||
x: value for x in f(x) | ||
Return: value of f(x) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a doctest:
>>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10)
79800.0
Then makes sure it passes locally with: python3 -m doctest -v maths/polynomial_evaluation.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss thanks for the suggestion!
will do the changes.
@cclauss you can review the changes now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are passing https://travis-ci.org/TheAlgorithms/Python/builds/591848844#L670
Thanks for your contribution. Congratulations!
* maths-polynomial_evalutation * added doctest and removed redundancy
Added code for evaluating a polynomail f(x) for a value of x.