Write a program in Python programming language, which allows the user to input an integer value. Based on the input values, the program should perform the following tasks:
⦁ If the entered value is negative then it should print “Factorial does not exist for negative numbers”.
⦁ If the entered value is 0 then it should print “The factorial of 0 is 1”.
⦁ Calculate and display the factorial of the given integer.
import math
def factorial():
try:
digit = int(input('Enter a number: '))
if digit < 0:
print('Factorial does not exist for negative numbers')
elif digit == 0:
print('The factorial of 0 is 1')
else:
print(math.factorial(digit))
except ValueError:
print("it's not a number")
factorial()
factorial()
Comments
Leave a comment