Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Cheating and Not with Notes solution in Clear category for Number With Exclamation by BootzenKatzen
'''
how to cheat:
'''
from math import factorial
'''
in the math module there's already a factorial function that does what we want
so we can just import that function
'''
def factorial_not_cheating(n: int) -> int:
fact = 1 # our starting number is always one
for i in range(1, n+1): # then starting from one, all the way through our indicated number
# (if you don't add one, then because of how range works, it stops 1 short)
fact = fact * i # take our current fact and multiply it by i
# so if n is 3 it would be 1 * 1, 1 * 2, 2 * 3 ending with 6
return fact # once you're done looping, return the final number!
print("Example:")
print(factorial(4))
# These "asserts" are used for self-checking
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(5) == 120
assert factorial(10) == 3628800
assert factorial(15) == 1307674368000
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 11, 2023