Scientific Computing Lab TM 1
import math
def main():
hasil = 0
print(“Eina Wenny Natasha M”)
print(“1601235666”)
print(“04PAW”)
print(“\n”)
print(“This program approximates the value of pi by summing of terms in a given series.\n”)
a = int(input(“Enter the number of terms to sum: “))
#Hitung
for x in range(1, a+1):
divisor = 2 * x – 1
if x % 2 == 0:
hasil = hasil – (4.0/divisor)
else:
hasil = hasil + (4.0/divisor)
print(“\nThe Result Data:”)
print(“The Value of math.pi = ” + str(math.pi))
print(“The Sum of the First %d Terms of This Series = ” %(a) + str(hasil))
print(“True Error(Et) = “, str(math.pi-hasil))
print(“True Fractional Relative Error = “, str((math.pi-hasil)/math.pi))
print(“True Percent Relative Error = “, str(((math.pi-hasil)/math.pi)*100), “%”)
main()
Eina Wenny Natasha Magdalena
1601235666
04 PAW

No Comments »
RSS feed for comments on this post. TrackBack URL