• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
0%
SHARE
TWEET

# Untitled

a guest Aug 12th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # -*- coding: cp1252 -*-
2. #leibniz.py
3. import math
4. def leibniz(n):
5.     nenner=1
6.     piLeibniz=0.0
7.     for counter in range(0,n):
8.         piLeibniz+=((-1.0)**counter)*4/nenner
9.         nenner+=2
10.     return (piLeibniz)
11.
12. def wallis(abweichung):
13.     m=1
14.     zaehler=2.0
15.     nenner=3.0
16.     piWallis_=2.0
17.     while ((abs(2*piWallis_-pi))>10**-7+abweichung):
18.         if m%2==0:
19.             piWallis_*=float(zaehler/nenner)
20.             nenner+=2
21.         else:
22.             piWallis_*=float(zaehler/nenner)
23.             zaehler+=2
24.         m+=1
25.
26.     return (m,piWallis_)
27.
28.
29. pi=math.pi
30. n=input("Bitte n eingeben: ")
31. piLeibniz=leibniz(n)
32.
33.
34. (m,piWallis_)=wallis(abs(piLeibniz-pi))
35. print "n=",n,", m=",m, ", Abweichung Leinbniz=",abs(piLeibniz-pi), ", Abweichung Wallis=",abs(2*piWallis_-pi)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top