resultado=0

numero=int(input("introduce numero para factorial: "))

for i in range(0,(numero+1)):

resultado=resultado+i*(i+1)

print(resultado)

0 votes

I think your main problem is that you didn't properly understand how the factorial is calculated.

Please, read it here.

So based on this, you could implement factorial with a for loop like this:

def factorial(n): product = 1 for i in range (2, n + 1): product *= i return product

I'd suggest trying to implement it with recursion as well (the function calls itself, instead of a for loop).

+1 vote

It can also be done using recursion.

First of all, you better try to understand What is factorial?

Then it will be very easy for you to get the correct answer.

if n==1 or n==0:

return 1

else:

return (n*factorial(n-1))

n=int(input("Enter any number: "))

print("Factorial of the given number",factorial(n))

Factorial is done using linear recursion.

...