Computer Science, asked by mamtateen7319, 1 year ago

Program to find factorial using for loop in python

Answers

Answered by PurnenduMajumder
1

Explanation:

#Python program find factorial of a number

#using while loop

num=int(input("Enter a number to find factorial: "))

#takes input from user

factorial=1; #declare and initialize factorial variable to one

#check if the number is negetive ,positive or zero

if num<0:

print("Factorial does not defined for negative integer");

elif(num==0):

print("The factorial of 0 is 1");

else:

while(num>0):

factorial=factorial*num

num=num-1

print("factorial of the given number is: ")

print(factorial)

Answered by sushiladevi4418
8

Answer:

Python program to find the factorial using for loop.

Explanation:

num = int(input("enter a number: "))

 fac = 1

 for i in range(1, num + 1):

fac = fac * i

 print("factorial of ", num, " is ", fac)

Output:

Enter a number: 3

6

Similar questions