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
2023-01-09 00:01:17 +02:00

20 lines
432 B
Python

# Lesson 2 Task 4: get number factorial
# Author: Stanislav Mykhailenko
# License: Unlicense
error = False
try: number = int(input("Enter a natural number: "))
except ValueError: error = True
if not error and number < 1: error = True
if not error:
factorial = 1
for i in range(2, number + 1):
factorial = factorial * i
else:
print(str(number) + " factorial is " + str(factorial))
else:
print("Invalid number entered.")