Answer to Question #348606 in Python for Talha

Question #348606

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.



1
Expert's answer
2022-06-06T08:57:06-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS