how to find factorial of a number?

0 votes
May 4, 2018 in Python by ana1504.k
• 7,870 points
31 views

1 answer to this question.

0 votes

You can find factorial by many ways. Either you use "math" module or write a complete function. For example: Calcuating the factorial of number 5

import math
print(math.factorial(5))

OR 

def factorial(n):

    if n == 0:

        return 1

    else:

        return n * factorial(n-1)

factorial(5)    

Output - 120

answered May 4, 2018 by aayushi
• 750 points

Related Questions In Python

0 votes
1 answer

How to find exponent of a number in Python?

Yes you can do it using the ...READ MORE

answered Jul 2 in Python by Arvind
• 2,960 points
18 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29 in Python by rajesh
• 1,210 points
80 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 216 views
+4 votes
6 answers
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
184 views
0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
87 views