Program that calculates a series of N terms

Asked

Viewed 36 times

1

Write a program to calculate the value of the series, for N terms.

S = 0 + 1/2! + 2/4! + 3/6! + ...

I started to do the program as shown in the code below, but I’m not getting the right result.

Please help me! Thank you!

def fatorial_for(numero):
    resultado = 1
    for k in range(1, numero + 1):
        resultado *= k
    return resultado

n = int(input('Digite um número inteiro positivo: '))
s = 0
for i in range(0, n + 1):
    for j in range(1, n + 1):
        s = s + (i / fatorial_for(j * 2))
print(s)

1 answer

1


In this passage:

for i in range(0, n + 1):
    for j in range(1, n + 1):
        s = s + (i / fatorial_for(j * 2))

does not make sense this second loop. Use:

for i in range(0, n + 1):
    s += i / fatorial_for(i * 2)
  • Wow, now that I’ve come to see that you really don’t need it, thank you very much!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.