Factorial

#!/usr/bin/evn python

# Take input from the user
num = int(input("Enter a number to calculate factorial: "))
factorial = 1

# Check if the number is negative, positive or zero
if num < 0:
    print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
    print("The factorial of 0 is 1")
else:
    # For loop iterating by sequence index
    for i in range(1,num + 1):
        factorial = factorial*i
    print("The factorial of",num,"is",factorial)
    
    
    
#***** Output *****
Enter a number to calculate factorial: 5
The factorial of 5 is 120

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!