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
5 Antworten
+ 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.
+ 3
@H... What do you mean?
(Sorry for not spelling out your full name. My English keyboard doesn't have the proper characters.)
+ 2
@R055A... That's a good question. I wouldn't know because I start to twitch when I do Python challenges. LOL
+ 1
@David tq bro
+ 1
return 1 but not return (1)