0

Can any give answer for the question mentioned below

def f(m): if m == 0: return(1) else: return(m*f(m-1)) Which of the following is correct?  The function always terminates with f(n) = n  The function always terminates with f(n) = factorial of n  The function terminates for non-negative n with f(n) = n  The function terminates for non-negative n with f(n) = factorial of n

13th Feb 2018, 4:48 AM
Sagar S
Sagar S - avatar
5 odpowiedzi
+ 3
@Sagar: The answer is the last option. The code is a classic factorial function that will recursively loop until the input has reduced to 0. If the input starts off less than zero, this recursive condition will never be satisfied and, therefore, never terminate.
13th Feb 2018, 5:27 AM
David Carroll
David Carroll - avatar
+ 3
@H... What do you mean? (Sorry for not spelling out your full name. My English keyboard doesn't have the proper characters.)
13th Feb 2018, 6:31 AM
David Carroll
David Carroll - avatar
+ 2
@R055A... That's a good question. I wouldn't know because I start to twitch when I do Python challenges. LOL
13th Feb 2018, 5:48 AM
David Carroll
David Carroll - avatar
+ 1
@David tq bro
13th Feb 2018, 5:29 AM
Sagar S
Sagar S - avatar
+ 1
return 1 but not return (1)
13th Feb 2018, 6:24 AM
Merer
Merer - avatar