diff --git a/Lesson_2/task4.py b/Lesson_2/task4.py index e7cc733..59f0cb9 100644 --- a/Lesson_2/task4.py +++ b/Lesson_2/task4.py @@ -2,24 +2,19 @@ # Author: Stanislav Mykhailenko # License: Unlicense -# Return codes: -# 0 - OK -# 1 - Invalid number entered - -import sys - -def numberError(): - print("Invalid number entered.") - sys.exit(1) +error = False try: number = int(input("Enter a natural number: ")) -except ValueError: numberError() +except ValueError: error = True -if number < 1: numberError() +if not error and number < 1: error = True -factorial = 1 +if not error: + factorial = 1 -for i in range(2, number + 1): - factorial = factorial * i + for i in range(2, number + 1): + factorial = factorial * i + else: + print(str(number) + " factorial is " + str(factorial)) else: - print(str(number) + " factorial is " + str(factorial)) + print("Invalid number entered.") \ No newline at end of file