Sobes.tech
Junior — Senior

Iterative and recursive methods of calculating factorial

livecode

Task condition

Describe the program's operation: what functions are declared, how the calculation of factorial is implemented using a loop and recursion, and what value will be printed during execution.

value = 1

def get_result(n):
    result = 1
    if n > 1:
        for i in range(2, n + 1):
            result *= i
    return result

def get_result2(n):
    if n == 0 or n == value:
        return value
    print(value)
    return n * get_result2(n - value)

if __name__ == '__main__':
    print(get_result(5))