Home > python > First 15 digits of PI

First 15 digits of PI

Look at this verse:

How I want a drink
alcoholic of course
After the heavy lectures
involving complex functions

Take the length of the words and you get the first 15 digits of PI. Here is the proof:

import sys
import math

s = """
How I want a drink
alcoholic of course
After the heavy lectures
involving complex functions
"""

print [len(w) for w in s.split()]
print math.pi

Output:

[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]
3.14159265359   # the last digit is rounded here

Read more on PI at http://www.eveandersson.com/pi/.

And if you didn’t know, here is the PI song :)

 
Update (20110317)

You can approximate the value of PI with 355/113. The first 6 decimal places are the same. It’s quite easy to memorize it: visualize 113355, split into two (113 and 355), then do the division.

>>> import math
>>> math.pi
3.1415926535897931
>>> 355/113.
3.1415929203539825

Ref.: Kee Nethery at python-list.

Categories: python Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: