+ 3
factorial using for loop
hey guys I made a factorial program using for loops and a list and it works so my question was is it better to use this or to use the recursion method coz I found this simpler and tell me if I have done a mistake anywhere. my code is : x = int (input (":")) y =1 list = list (range (1, (x+1))) for i in list: y*=I print (y)
8 ответов
+ 2
I see and hey can u just tell me what does recursion exactly mean
+ 2
i see
+ 2
thanks alot
+ 2
I tried both in py and SL seems to use more resource with recursion (you get bigger factorial with for loop before "time limit exceeded" msg)
https://code.sololearn.com/cRR0883g759i/?ref=app
https://code.sololearn.com/ciZe5KbLj3hT/?ref=app
+ 1
Recursion is much easier for me
def factorial(n):
return n * factorial(n - 1) if n > 1 else 1
Num = 4
print("factorial of", Num, "is :", factorial(Num))
0
It means function call itself under certain conditions
0
nice
0
You had placed 'I' in place of 'i' inside for loop
But anyways,
Good job !
Here is mine
# Using Python
https://code.sololearn.com/cM4VQXlTNKYF/?ref=app