#!/usr/bin/env python
# Python Script for counting didgets in pi.
# Written January 19, 2018 - Coty R Miller
_piString="3.14159265"
#
# You can feed this script a file of many didgets named "one-million.txt" by removing the line 5
# and removing comment tags from lines 12 and 13.
#
#with open("one-million.txt") as myfile:
# _piString="".join(line.rstrip() for line in myfile)
_pi=list(_piString)
i=0
#
# Number integers, for holding the tally.
#
_zero=0
_one=0
_two=0
_three=0
_four=0
_five=0
_six=0
_seven=0
_eight=0
_nine=0
_nonNumerical=0
print "Couting Didgits... (", len(_pi), ")"
print ""
#
# This loop reads all didgets and counts them.
#
while i < len(_pi):
if _pi[i] == "0": # If number is 0
_zero = _zero + 1 # Then add one to the tally.
elif _pi[i] == "1":
_one = _one + 1
elif _pi[i] == "2":
_two = _two + 1
elif _pi[i] == "3":
_three = _three + 1
elif _pi[i] == "4":
_four = _four + 1
elif _pi[i] == "5":
_five = _five + 1
elif _pi[i] == "6":
_six = _six + 1
elif _pi[i] == "7":
_seven = _seven + 1
elif _pi[i] == "8":
_eight = _eight + 1
elif _pi[i] == "9":
_nine = _nine + 1
else:
_nonNumerical = _nonNumerical + 1 # For else. We'll tally it as a non-number
i = i + 1
#
# Print the results.
#
print "Results are as follows:"
print "Zero - ", _zero
print "one - ", _one
print "two - ", _two
print "three - ", _three
print "four - ", _four
print "five - ", _five
print "six - ", _six
print "seven - ", _seven
print "eight - ", _eight
print "nine - ", _nine
print " - - - - - - - - - - - - "
print _nonNumerical, " - Non-Numerical Charecters ignored."
print " - For faster proccessing feed me a file with fewer non-numerical charecters."
print "