The difference between the two methods is in the second case if the condition. In the first method, if condition is "if num and lt; = 1" and in the second method if condition is "if num = 1" I have mapped the steps of step-paper on both methods, but I do not understand Why does factual 2 give 1 rather than 6. On paper, I get 6 for both methods.
def factorial1 (number) if the number is & lt; 0 Return to "Please use a positive number" end if num & lt; = 1 1 Other Issue * Functional (num-1) End Factorial 1 (3) # Layer 6 def factorial2 (num) if num & lt; Return "Please use a positive number" end if num = 1 1 and num * factorial (num-1) puts the end end factorial2 (3) # layer 1
if num = 1
Comparator operator is ==
, No =
(assignment operator).
In addition to not using the return keyword, it is a good conference to return something to each branch.
Comments
Post a Comment