Quick actions

cmd+k|ctrl+k

Navigation

Languages

Exercise: Factorial

Snippet info

Language

Python

Visibility

public

Author

rakeshbhatia87

Created

2023-01-09T01:16:15.745058Z

Updated

2023-01-09T01:39:09.407471Z

# Write two functions that finds the factorial of any number. One should use recursive, the other should just use a for loop

def findFactorialRecursive(number):
    #code here
    if number == 0 or number == 1:
        return 1
    return number*findFactorialRecursive(number-1)

def findFactorialIterative(number):
    #code here
    if number == 0 or number == 1:
        return 1
    res = 1
    for i in range(1, number+1):
        res *= i
    return res

#answer = findFactorialRecursive(1)
#print(answer)
answer = findFactorialIterative(1)
print(answer)
INFO