Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created August 30, 2021 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamelafox/a7135b8c6788680db4a0ca15f602085e to your computer and use it in GitHub Desktop.
Save pamelafox/a7135b8c6788680db4a0ca15f602085e to your computer and use it in GitHub Desktop.
Product of numbers
"""
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