We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 9: Recursion 3
Day 9: Recursion 3
+ 22 comments Use Function name as "factorial" rather to use any other like f or fact.
After that your all testcase will be pass.
+ 13 comments In Python 3.
We know that factorial of 1 and 0 is 1, after that we have what we have
def factorial(n): if n <= 1: return 1 else: result = n * factorial(n - 1) return result
+ 4 comments factorial = lambda x : 1 if x<=1 else x*factorial(x-1) print(factorial(int(input())))
+ 6 comments Here's my simple solution in Java:
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println( factorial(scan.nextInt()) ); } public static long factorial( int n ) { return (n == 1) ? 1 : n*factorial(n-1) ; } }
+ 11 comments The computed values is printed properly, the function has the name factorial and it fails with this message:
Traceback (most recent call last): File "/custom-E0P65VURzzcASfYoaTsm/solution.py", line 69, in <module> data["signals"] = map( int, open( "signal00.sig" ).read().strip().split() ) IOError: [Errno 2] No such file or directory: 'signal00.sig'
What is wrong?
Load more conversations
Sort 1014 Discussions, By:
Please Login in order to post a comment