2
How to calculate series in Python? I created an algorithm but I’m not getting to the final goal.
Ex:
S1 = x + (x-1) + (x – 2) + ... + (x – n)
S2 = 1 + 1 +1 + 1 +2 + … 1
I entered with an initial number and an ending, but the result is giving error. My code:
while True:
try:
value1 = int(input("Digite o número inicial: "))
value2 = int(input("Digite o numero final: "))
for i in range(value1,value2):
num1 = value1 +(value1-1)+(value1-2)+(value1 - value2)
i += 1
print("Valor é: ",num1)
break
break
except ValueError:
print("Obs: Somente números inteiros! Tente novamente...\n")
Apparently the S2 is
S2 = lambda x, n: (n+1)*(x +n/2)
; as if it were the series 1 only, instead of subtracting x by something, it adds x with that same something– Jefferson Quesado
@Jeffersonquesado at first seemed, but this factor 1 that appears in all terms generated me strangeness. I believe it would be a fraction: 1/x + 1/(x+1) + 1/(x+2) + ...
– Woss