In: Computer Science
Exercise: Write a program named factorial.py that contains the following two functions:
def while_factorial(num)
def for_factorial(num)
These should calculate the factorial of a given number represented by the argument num using a while loop and a for loop respectively.
#function for calculating factorial using while loop
def while_factorial(num):
f=1
c=1
while(c<=num):
f=f*c
c=c+1
print("while_factorial: factorial of {} is
{}".format(num,f))
#function for calculating factorial using while loop
def for_factorial(num):
f=1
for c in range(1,num+1,1):
f=f*c
print("for_factorial: factorial of {} is
{}".format(num,f))
num=int(input("Enter number for factorial :"))
#reading number from user
#displaying factorial value using functions
while_factorial(num)
for_factorial(num)
-------------------------------------------------------------------------