This library was inspired by this meme:
Now we can easily solve it in less than a second!
Install the library with:
pip install -U py-digits
from pydigits import sum_pi_digits
print(sum_pi_digits(31_415, 'odd'))
# 78662
print(sum_pi_digits(31_415, 'odd', 'binary'))
# 10011001101000110
function pydigits.pi_digits(decimals)
Function that returns the pi
number rounded to the number of digits given has an argument.
- decimals:
int
. Number of digits ofpi
requested.
function sum_pi_digits(decimals, nature="all", notation="decimal")
-
decimals:
int
. Number of digits ofpi
requested. -
nature:
"all"
,"even"
or"odd"
, default"all"
. The nature of the digits ofpi
taht you want to count for your sum. -
notation:
"decimal"
or"binary"
, default"decimal"
. The notation of the answer obtained.
Run the test suite with:
python -m unittest tests
To install it locally from the source code:
python setup.py develop