Add Lesson 2 Task 4
This commit is contained in:
parent
ca319994ca
commit
0b11b0477f
1 changed files with 20 additions and 0 deletions
20
Lesson_2/task4.py
Normal file
20
Lesson_2/task4.py
Normal file
|
@ -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)))
|
Reference in a new issue