[PyAR2] Programming Challenge II - One is the Magic Number
phi3d at yahoo.com
Tue Oct 28 03:18:23 CET 2008
Here's my entry. It's your basic brute force model. I knew that others would find a more elegant way to do it, so I decided to make a generalized version that could count any digit from any number.
#Gordon Fisher Oct 27, 2008
print "This program counts the number of times a single digit appears in a series of numbers from 0 to a selected number."
Xstring = raw_input("Please enter a Number then press Enter, do not include commas: ")
keynumstring = raw_input("Please enter a number from 0-9 that you wish to count then press Enter,: ")
magicnum = int(Xstring)
total = 0
xlen = 0
for x in range(magicnum +1):
Xstring = str(x)
xlen = len(Xstring)
stringtotal = Xstring.count(keynumstring,0,xlen)
total = total + stringtotal
print "The number " + str(keynumstring) + " appears " + str(total) + " times."
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyAR2