Frequently Asked Python Program 3: How To Find Factorial of A Number

Frequently Asked Python Program 3: How To Find Factorial of A Number

SDET- QA

4 года назад

68,846 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

LOGAVIGNESH P
LOGAVIGNESH P - 30.10.2023 09:58

In recursion if everytime when factorial(n-1) calls the function won't it go in negative direction, 4*3*2*1*0*-1 likewise?

Ответить
Kevin Vélez
Kevin Vélez - 10.10.2023 23:27

def factorial(num):
if num < 2:
return num
return num * factorial(num-1)
print(factorial(5))

Ответить
Kevin Vélez
Kevin Vélez - 10.10.2023 23:25

def factorial(num):
fact = 1
for i in range(1, num+1):
fact *= i
return fact
print(factorial(5))

Ответить
Manuel Meekattukulam
Manuel Meekattukulam - 08.07.2023 04:12

Very helpful! Thanks!

Ответить
Vishwas Nagaraju
Vishwas Nagaraju - 12.02.2023 22:15

Factorial of a number.

num=-1
i=0
if num<0:
print("Factorial doesn't exist")
elif num==0:
print("Factorial is 1")
else:
for i in range(1,num):
num=num*i
print("Factorial is", str(num))

Ответить
Prime Vandal
Prime Vandal - 25.08.2022 17:31

thankelu velimach

Ответить
nithinraj chittath
nithinraj chittath - 23.08.2022 09:56

In recursive method there is no statement for when we input negative numbers.

Ответить
Sandeep tale
Sandeep tale - 06.07.2022 20:39

where can I find the all of these questions.

Ответить
Michaela Jašková
Michaela Jašková - 12.10.2021 02:13

Hi, if I want to have factorial for more numbers (3,4,5,..) how do I write the list of all numbers? THank you.

Ответить
sathya ganesh
sathya ganesh - 19.03.2021 20:01

good

Ответить