From ea949f4325bddb773a211fcaa39cbf04cc5f8683 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Thu, 3 Nov 2022 19:33:19 +0200 Subject: [PATCH] Make Lesson 2 Task 4 not use math library --- Lesson_2/task4.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lesson_2/task4.py b/Lesson_2/task4.py index ac53bfe..e7cc733 100644 --- a/Lesson_2/task4.py +++ b/Lesson_2/task4.py @@ -6,7 +6,7 @@ # 0 - OK # 1 - Invalid number entered -import math, sys +import sys def numberError(): print("Invalid number entered.") @@ -17,4 +17,9 @@ except ValueError: numberError() if number < 1: numberError() -print(str(number) + " factorial is " + str(math.factorial(number))) +factorial = 1 + +for i in range(2, number + 1): + factorial = factorial * i +else: + print(str(number) + " factorial is " + str(factorial))