You can copy-paste this code to follow along at this point in the lesson:
# Using for loop
def fact_loop(num):
if num < 0:
return 0
if num == 0:
return 1
factorial = 1
for k in range(1, num + 1):
factorial = k * factorial
return factorial
# Using recursion
def fact_recursion(num):
if num < 0:
return 0
if num == 0:
return 1
return num * fact_recursion(num - 1)
sebastianjliam on Jan. 6, 2022
Hi, when I run my program using
def fact_loop
and callfor fact_loop(10)
to check the factorial of 10 I’m not getting an output in the console. Am I missing something?