2022-10-14 22:03:25 +00:00
|
|
|
import math
|
|
|
|
|
2023-01-30 16:48:43 +00:00
|
|
|
|
2022-10-14 22:03:25 +00:00
|
|
|
def leibnizPi4(n):
|
|
|
|
total = 0
|
2023-05-16 20:18:38 +00:00
|
|
|
for x in range(1, n + 1):
|
|
|
|
increment = 1 / (x * 2 - 1)
|
2023-01-30 16:48:43 +00:00
|
|
|
total += -increment if x % 2 == 0 else increment
|
2022-10-14 22:03:25 +00:00
|
|
|
return total
|
|
|
|
|
2023-01-30 16:48:43 +00:00
|
|
|
|
2022-10-14 22:03:25 +00:00
|
|
|
def main():
|
|
|
|
num = int(input('Introduza o número de termos: '))
|
2022-10-18 17:18:56 +00:00
|
|
|
print(f"""
|
|
|
|
Resultado da série de Leibniz: {leibnizPi4(num)}
|
2023-05-16 20:18:38 +00:00
|
|
|
Valor do PI/4: {math.pi / 4}
|
2022-10-18 17:18:56 +00:00
|
|
|
""")
|
2022-10-14 22:03:25 +00:00
|
|
|
|
2023-01-30 16:48:43 +00:00
|
|
|
|
2022-10-18 17:18:56 +00:00
|
|
|
if __name__ == "__main__":
|
2023-01-30 16:48:43 +00:00
|
|
|
main()
|