Factorial

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

GE3171 – Problem Solving and Python Programming Laboratory Page No:

Ex. No: 4.1

Find Factorial of a number


Date:

AIM:

To Develop the Python Program for Find Factorial of a Number.

ALGORITHM:

Step 1: Start Process


Step 2: Define a function using def keyword with an parameter n
Step 3: If n==1 or n==0 return value 1
Step 4: Else return n*factorial (n-1)
Step 5: Read n variable from user input
Step 6: Display factorial by calling function (n)
Step 7: Stop process

PSEUDOCODE:

START
DEF factorial (n)
IF n==1 or n==0 THEN
RETURN 1
ELSE
RETURN n*factorial(n-1)
END IF
READ n
DISPLAY factorial(n)
STOP

IMPLEMENTATION CODE:

def factorial(n):

if n==1 or n==0:

return n

else:

return n*factorial(n-1)

n=int(input("Enter a num"))

Name:K.Suvetha Roll Number:23IT57 Branch: B.Tech


IT
GE3171 – Problem Solving and Python Programming Laboratory Page No:

print(factorial(n))

OUTPUT:

CASE 1:

CASE 2:

CASE 3:

RESULT:

The Python Code for Find Factorial of a Number is Written and Executed Successfully.

Name:K.Suvetha Roll Number:23IT57 Branch: B.Tech


IT

You might also like