From 0b11b0477f48ebbb9e696a6e73bfa44e721aa9ea Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Thu, 27 Oct 2022 18:54:57 +0300 Subject: [PATCH] Add Lesson 2 Task 4 --- Lesson_2/task4.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Lesson_2/task4.py diff --git a/Lesson_2/task4.py b/Lesson_2/task4.py new file mode 100644 index 0000000..ac53bfe --- /dev/null +++ b/Lesson_2/task4.py @@ -0,0 +1,20 @@ +# 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)))