Комментарии:
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?
Ответитьdef factorial(num):
if num < 2:
return num
return num * factorial(num-1)
print(factorial(5))
def factorial(num):
fact = 1
for i in range(1, num+1):
fact *= i
return fact
print(factorial(5))
Very helpful! Thanks!
Ответить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))
thankelu velimach
ОтветитьIn recursive method there is no statement for when we input negative numbers.
Ответитьwhere can I find the all of these questions.
ОтветитьHi, if I want to have factorial for more numbers (3,4,5,..) how do I write the list of all numbers? THank you.
Ответитьgood
Ответить