KnowledgeBoat Logo
|

Computer Science

Write a program to accept a number and display the factorial of that number.

Python

Python Control Flow

6 Likes

Answer

number = int(input("Enter a number: "))
factorial = 1
if number < 0:
    print("Factorial is not defined for negative numbers.")
else:
    for i in range(1, number + 1):
        factorial *= i
    print("The factorial of", number, "is", factorial)

Output

Enter a number: 5
The factorial of 5 is 120

Answered By

4 Likes


Related Questions