Hi all,
I am new to scientific python. While trying to follow the code below i always get "Factorial does not exist" response. I am using python 3.8 but the code is written in python 2.7 and it works. I have broken the code and ran it piecewise, still the code will not work properly when i enter i.e. 6 for n etc...integers greater than 1. I am out of tricks so please help me understand this factorial code: Thank you very much in advance!
I am new to scientific python. While trying to follow the code below i always get "Factorial does not exist" response. I am using python 3.8 but the code is written in python 2.7 and it works. I have broken the code and ran it piecewise, still the code will not work properly when i enter i.e. 6 for n etc...integers greater than 1. I am out of tricks so please help me understand this factorial code: Thank you very much in advance!
f = 1
n = input("Enter a value for n:")
if isinstance(n, int): #check whether the value is integer
if n == 1 or 0:
print ("Execution at if ")
print ("The value of {}! = {}" .format(n, f))
exit
elif n < 0:
print ("Execution at elif ")
print ("n is negative")
else:
print ("Executoin at else")
for i in range(2, n+1):
f *= i
print ("The value of {}! = {}" .format(n, f))
else:
print ("Factorial does not exist")
