Trying to finding equation for factorials

45 Views Asked by At

I am looking to find the factoral for N! but we cannot use the factorial function the equation I entered gives me numbers that are almost correct but not quite like when I enter 10 it gives me 36288000 when it should be giving me 3628800

declare getInt()

def getInt():

getInt = int
done = False

while not done:

# write "this program calculates N!"

    print("This program calcultes N!")

# get input for "N

    N = int(input("Please enter a non-negative value for N: "))


# if N < 0 then
    if N < 0:

        print("Non-Negative integers, please!")

    # else

    else:

# done = true

        done = True
# return N

return N

main

def main():

n = getInt()



for i in range(n):
    n = n * (i+1)

print("=",n)

main()

1

There are 1 best solutions below

0
On BEST ANSWER

make the range(n-1). if you don't do this in the last loop you are multiplying the result by the number itself which is not definition of factorial. factorial of a number means the product the number and all the integers less than it but greater than zero. and zero factorial is one