0
Data n, print the value of
Sn = 1/n + 2/(n-1) + 3/(n-2) + ... + n.
This is what I tried to do:
n =2
soma =1
for i in range(1,n+1):
if n>i:
soma+=i/n + i/(n-1)
But it only works when n=2. Someone could help?
0
Data n, print the value of
Sn = 1/n + 2/(n-1) + 3/(n-2) + ... + n.
This is what I tried to do:
n =2
soma =1
for i in range(1,n+1):
if n>i:
soma+=i/n + i/(n-1)
But it only works when n=2. Someone could help?
Browser other questions tagged python-3.x
You are not signed in. Login or sign up in order to post.
I’m sorry for the ignorance, but this sequence is strange. It implies that the values will eventually converge on
n
, but in fact they will converge onn+1/(n-n)
, in which you will get a division error by 0. This sequence is right?– Andre
@Andre withdrew from an exercise; https://www.ime.usp.br/~Cris/lessons/08_1_110/abril.html
– Ed S
@Andre pulled from one exercise - Problem 10.1:; https://www.ime.usp.br/~Cris/lessons/08_1_110/abril.html
– Ed S
Well, in the exercise itself has an example of C implementation, which converted to Python would be thus, I guess you can use it as a reference, it’s your tie
for
that is doing more thing.– Andre
@Andre did not understand (i+1)/(n-i)
– Ed S
It’s the general term of your series
– Woss
@Woss really did not understand how this general term was arrived at
– Ed S