Header Ads

Python - WAP To Print Factorial of a Number in Python - 01

This is a program to print the Factorial of any given Number in Python.


#!/usr/bin/python3
while True:

    num = int(input("Enter a Number : "))

    factorial = 1

    if ( num < 0 ):
        print ("Factorial of a Negative Value don't exist!")
    elif ( num == 0 ):
        print ("The Factorial of '0' is always '0'")
    else:
        for idx in range(1, num + 1):
            factorial = factorial * idx
        print ("The Factorial of '%d' is '%d'" % (num, factorial))

    print ("Codegig.org")
    
    if (input("To continue press ['y'/n] : ")) == 'y':
        continue
    else:
        break

Program Output: 

No comments