This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
NG_2022_Stanislav_Mykhailenko/Lesson_2/task4.py
Stanislav Mykhailenko 0b11b0477f
Add Lesson 2 Task 4
2022-10-27 18:54:57 +03:00

20 lines
419 B
Python

# Lesson 2 Task 4: get number factorial
# Author: Stanislav Mykhailenko
# License: Unlicense
# Return codes:
# 0 - OK
# 1 - Invalid number entered
import math, sys
def numberError():
print("Invalid number entered.")
sys.exit(1)
try: number = int(input("Enter a natural number: "))
except ValueError: numberError()
if number < 1: numberError()
print(str(number) + " factorial is " + str(math.factorial(number)))