Student attempts to solve a recursion problem in 1 minute #python #coding #recursion

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

def factorial(n) :
if n==0 or n==1:
return 1
else:
return n* factorial(n-1)

VideoGames_Wizard
Автор

# recursive factorial function
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)

bayramgun
Автор

Def factorial(n):
If N==0:
Return 1
Else:
Return n* factorial (n-1)

I hope this is right.

Please ignore indentation as I'm typing through phone!!

ashishgupta
Автор

in c:
int factorail(n):
if n < 2
return (n);
return (factorial(n - 2) + factorial(n - 1));

AliRezaShirzad-qq
Автор

<?php

function factorial($n){
if($n==0){
return 1;
}
return $n * factorial($n-1);
}
echo(factorial(4));
?>

result= 24

aamb_c
Автор

line 10 = " return 1"
line 11 = " return n * factorial(n-1)"

iaroslav
Автор

there's only one bug and it's this short

asilbekabdurashidov
Автор

if n == 0
return n
return n *factorial(n-1)

jayvondied
Автор

Def factorial(n)
res = 0
If n ==0
return 0
else: for i in range(1, n+1)
res *= i


???

joshuamontalvanpoppe
Автор

Why doing it when GPT4 can do it way better than you?

longmai