9
Make a program that calculates and writes the sum of the n first series terms:
Input format An integer n indicating the number of terms in the series
Output format A floating point number formatted to two decimal places, followed by a line end.
Input example: 5 Exit: 3.46
This question is from thehuxley.com, when submitting the question of this error: "The result of the evaluation was 'WRONG_ANSWER' which means that your program did not return the expected answer."
Only I’ve done several tests with higher values and the result is expected... I have no idea what the test case is that is generating the wrong value. Does anyone know?
def fatorial(number):
if number == 0:
return 1
else:
return number * fatorial(number - 1)
n = int(input())
count, value = 0, 0
for number in range(1, n + 1):
count += count + 1
if(number % 2 == 0): # par
value -= fatorial(number) / count
else:
value += fatorial(number) / count
print("%.2f" % value)
It is not the lack of the end-of-line character?
– Luiz Vieira