Calculate Factorial of a Given Number in Python

def factorial(x):

if x<0:

return “Error: negative number”

y=1

while x>0:

y=y*x

    x=x-1
return y

i=eval(input(“Enter number : “))

print(factorial(i))

#Note : python differentiates between blocks of code through indentation so before running the code do not forget to indent it properly.

About these ads

About b4blogger
I am a student and a blogger who wants to share my knowledge with the world.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: