uaveiro-leci/1ano/fp/aula04/leibnizPi4.py

20 lines
394 B
Python
Raw Normal View History

2022-10-14 22:03:25 +00:00
import math
def leibnizPi4(n):
total = 0
for x in range(1, n+1):
if x % 2 == 0:
total -= 1/(x*2-1)
else:
total += 1/(x*2-1)
return total
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)}
Valor do PI/4: {math.pi/4}
""")
2022-10-14 22:03:25 +00:00
2022-10-18 17:18:56 +00:00
if __name__ == "__main__":
main()