From ce0b178783d175140e94317f232210f13bffd243 Mon Sep 17 00:00:00 2001 From: madforpython <50396857+madforpython@users.noreply.github.com> Date: Tue, 1 Oct 2019 21:43:05 +0530 Subject: [PATCH] Update factorial_python.py --- maths/factorial_python.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/maths/factorial_python.py b/maths/factorial_python.py index 6c1349fd5f4c..2496320a79f2 100644 --- a/maths/factorial_python.py +++ b/maths/factorial_python.py @@ -1,19 +1,19 @@ -"""Python program to find the factorial of a number provided by the user.""" +# Python program to find the factorial of a number provided by the user. # change the value for a different result -NUM = 10 +num = 7 # uncomment to take input from the user -# num = int(input("Enter a number: ")) +#num = int(input("Enter a number: ")) -FACTORIAL = 1 +factorial = 1 # check if the number is negative, positive or zero -if NUM < 0: - print("Sorry, factorial does not exist for negative numbers") -elif NUM == 0: - print("The factorial of 0 is 1") +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") else: - for i in range(1, NUM + 1): - FACTORIAL = FACTORIAL * i - print("The factorial of", NUM, "is", FACTORIAL) + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial)