Saturday, 19 February 2022

Program to compute the factorial of a number

CODE 

# factorial. py 

# Program to compute the factorial of a number 

# Illustrates for loop with an accumulator 

def main() : 

    n = int (input ("Please enter a whole number: ") ) 

    fact = 1 

    for factor in range(n,1,-1) : 

        fact = fact * factor 

    print ("The factorial of", n, "is", fact) 

main ()


NOTE : save above program as factorial.py

SCREENSHOT



No comments:

Post a Comment