From 3407cadde02741457b3e7fb03ddaa6936bb1d6f8 Mon Sep 17 00:00:00 2001 From: tejaswari7 Date: Fri, 16 Oct 2020 22:00:54 +0530 Subject: [PATCH] Factorial Exception Handling and made it dynamic --- Python/Factorial_Calculator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Python/Factorial_Calculator.py b/Python/Factorial_Calculator.py index b7c19f1..93ebff4 100644 --- a/Python/Factorial_Calculator.py +++ b/Python/Factorial_Calculator.py @@ -1,11 +1,11 @@ -# Python 3 program to find -# factorial of given number def factorial(n): # single line to find factorial return 1 if (n==1 or n==0) else n * factorial(n - 1); -# Driver Code -num = 5; -print("Factorial of",num,"is", -factorial(num)) \ No newline at end of file +try: + num = int(input("Enter Number:\t")); + print("Factorial of",num,"is",) + factorial(num) +except ValueError: + print("Enter Number only")