Make a program that computes and writes the sum of the n first terms of the series:
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 one end of the line.
Input example: 5 Exit: 3.46
This question is from thehuxley.com site, when submitting the issue for this error: "The result of the evaluation was 'WRONG_ANSWER' which means your program did not return the expected response."
I have already done several tests with larger values and the result is as expected ... I have no idea what the test case is generating the wrong value. 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)