Created
August 30, 2021 06:28
-
-
Save pamelafox/a7135b8c6788680db4a0ca15f602085e to your computer and use it in GitHub Desktop.
Product of numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This function should return the product | |
of all the numbers from 1 to the given end number | |
(including the end number). | |
It is mostly written for you, but it has several bugs! | |
Tips for debugging: | |
* Read through the code and trace it on paper for small inputs | |
* Try running the tests and observe the output | |
* If you have a hunch, try changing the code and seeing how the output changes | |
""" | |
def product_of_numbers(end): | |
""" | |
>>> product_of_numbers(1) | |
1 | |
>>> product_of_numbers(2) | |
2 | |
>>> product_of_numbers(3) | |
6 | |
>>> product_of_numbers(10) | |
3628800 | |
""" | |
result = 1 | |
counter = 0 | |
while counter < end: | |
result *= counter | |
counter += 2 | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment