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

18 lines
421 B
Python
Raw Permalink Normal View History

2022-10-27 15:54:57 +00:00
# Lesson 2 Task 4: get number factorial
# Author: Stanislav Mykhailenko
# License: Unlicense
try:
number = int(input("Enter a natural number: "))
if number < 1:
raise ValueError("A natural number is required.")
2022-10-27 15:54:57 +00:00
factorial = 1
for nextNumber in range(2, number + 1):
factorial = factorial * nextNumber
print(str(number) + " factorial is " + str(factorial))
except ValueError:
print("Invalid number entered.")