+1 vote
in Python by
Write a python program to print the factorial of a number.

1 Answer

0 votes
by

Below is the code to print the factorial of a number:

We start off by taking an input which is stored in ‘num’. Then, we check if ‘num’ is less than zero and if it is actually less than 0, we print out ‘Sorry, factorial does not exist for negative numbers’.

After that, we check,if ‘num’ is equal to zero, and it that’s the case, we print out ‘The factorial of 0 is 1’.

On the other hand, if ‘num’ is greater than 1, we enter the for loop and calculate the factorial of the number.

Related questions

+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
0 votes
asked Jan 18, 2021 in Python by SakshiSharma
...