• Uncategorized

Python Program to Find the Factorial of a Number

In this example, we will write a simple program to take input number from the user and display the factorial of the number. To better understand this example, make sure you have knowledge of the following tutorials:-

The factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n.

Python Program to Find the Factorial of a Number

number = int(input("Enter a number: "))
if number < 0:
   print("Factorial doesn't exists for negative number !!!")
elif number == 0:
   print("The factorial of 0 is 1")
else:
    factorial = 1
    for i in range(1, number + 1):
        factorial *= i
    print("The factorial of", number, "is", factorial)

The output of the above program is:-

Enter a number: 5
The factorial of 5 is 120
SHARE Python Program to Find the Factorial of a Number

You may also like...


Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Attempt to read property "cat_name" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 14

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/functions.php on line 37

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15
Share