Advertisement
Adehumble

Week3 Coding Exercise 10

Feb 11th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. #10
  2. #This program is written to evaluate the factorial of any number using Recursion method provided the number is neither a negative integer nor a float
  3. def factorial(num):  
  4.    if num== 1:  
  5.        return num
  6.    else:  
  7.        return num*factorial(num-1)  
  8.      
  9. user_value= int(input("Enter any positive number: "))  
  10. if user_value< 0:  
  11.    print("Ooops! factorial does not exist for negative numbers.\nPlease try again!")
  12. elif user_value == 0:  
  13.    print("The factorial of 0 is 1")  
  14. else:  
  15.    print("The factorial of",user_value,"is",factorial(user_value))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement