Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:24:28+00:00 2026-06-09T08:24:28+00:00

Write a function estimatePi() to estimate and return the value of Pi based on

  • 0

Write a function estimatePi() to estimate and return the value of Pi based on the formula found by an Indian Mathematician Srinivasa Ramanujan. It should use a while loop to compute the terms of the summation until the last term is smaller than 1e-15. The formula for estimating Pi is given below:
As per Ramanujam’s estimation

(I’m sorry, I’m unable to upload the image)

def estimatePi():
import math
def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)
k=0
final=0
pi=0
while pi<1e-15:
    a=factorial(4*k)
    b=(1103+26390*k)
    c=factorial(k)
    d=c**4
    e=396**(4*k)
    f=2*math.sqrt(2)/9801
    final+=(a*b*f)/(d*e)
    k+=1
    pi=1/final
return pi

and, my problem is this:
Expected answer was =3.14159265359
my answer is =3.14159273001

I was not able to find my fault :(. Can anyone help with this for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:24:29+00:00Added an answer on June 9, 2026 at 8:24 am

    You answer is correct. Float numbers have problems with accuracy especially for large number of digits after the decimal point; and when calculating non-exact values.

    You can see from your answer that it has estimated the value of pi correctly for 5 digits after the decimal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I write this function, but what's its return value. (defn read-data [file] (let [code
I should write function that takes list, element and return positions in with such
if i write: function myindex(name){ var cut_point = name.lastIndexOf('_')+1; return name.substring(cut_point); } ... var
I'm learning to use the write function and am trying to print only a
I'm trying to write function in C# that will converts JSON to a key/value
I'm trying to write function similar to http://whatismyudid.com/ that, then approved, will return the
I know JFile and write function in Joomla 1.6 but is there a similar
I'm trying to write function to do the number_format() job for the non-ascii numbers
I have a simple file read and write function. private void WriteToFile(String filename, String
I was trying to make a Read\Write function for websocket but i've a problem...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.