fakult c3 a4t python

Solutions on MaxInterview for fakult c3 a4t python by the best coders in the world

showing results for - "fakult c3 a4t python"
Paul
01 Mar 2020
1def factorial(num): 
2    if num < 0: 
3        print("Factorial of negative num does not exist")
4    elif num == 0: 
5        return 1
6    else: 
7        fact = 1
8        while(num > 1): 
9            fact *= num 
10            num -= 1
11        return fact 
12num = 5; 
13print("Factorial of",num,"is", factorial(num)) 
14
Baylee
11 Jan 2019
1 pythonCopydef factorial(num): 
2    if num < 0: 
3        print("Factorial of negative num does not exist")
4
5    elif num == 0: 
6        return 1
7        
8    else: 
9        fact = 1
10        while(num > 1): 
11            fact *= num 
12            num -= 1
13        return fact 
14
15num = 5; 
16
17print("Factorial of",num,"is", factorial(num)) 
18
Mats
22 Nov 2019
1def factorial(n): 
2    return 1 if (n==1 or n==0) else n * factorial(n - 1);  
3num = 5; 
4print("Factorial of",num,"is", factorial(num))
5