1#Factorial
2'''factorial n! - n* n-1*n-2..1'''
3
4def fac_iterative_method(n):
5 fac = 1
6 for i in range(n):
7 fac = (fac * (i+1))
8 print('fac of',i+1,'=',fac)
9
10number = int(input('enter the number'))
11fac_iterative_method(number)
12
1# change the value for a different result
2num = int(input('enter a number'))
3# To take input from the user
4#num = int(input("Enter a number: "))
5factorial = 1
6# check if the number is negative, positive or zero
7if num < 0:
8 print("Sorry, factorial does not exist for negative numbers")
9elif num == 0:
10 print("The factorial of 0 is 1")
11else:
12 for i in range(1,num + 1):
13 factorial = factorial*i
14 print("The factorial of",num,"is",factorial)
15