I built a short presentation demonstrating the use of CodeSkulptor3 (Python 3).
Feel free to follow the links and to offer a critique.
CodeSkulptor3 is a free Python language 'sandbox' for messing around with simple programs
Probability of finding exactly one digit “7” in the range of numbers from 0 to 10^x exclusive
Example 1:
probability in the range of numbers from 0 to 9 (all one-digit numbers)= 0.10
[7]
Example 2:
probability in the range of numbers from 0 to 99 (all two-digit numbers)= 0.18
[7, 17, 27, 37, 47, 57, 67, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 87, 97]
Link to my coding screenshot
Link to my chart screenshot
Code Text
# digit we are trying to match match = '7' # my_maxes will be a list from 10 to 10^30 # my_maxes = [10, 100, 1000 ... ] my_exponents = range(31) my_maxes = [10**k for k in my_exponents] # verify print(my_exponents) print(my_maxes) xs = [e for e in my_exponents] ys = [] for exponent in my_exponents: ans = (exponent)*9**(exponent-1) possible = 10**exponent ratio = exponent/10*0.9**(exponent-1) #print(possible, ans, ans/possible) ys.append(ratio) print(exponent, possible, ans, ratio) print("\n---") import simpleplot # verify print(xs) print(ys) dataset = list(zip(xs,ys)) # verify print(dataset) # pops up a line plot simpleplot.plot_lines('My Answer', 400, 300, 'exponent of 10', 'probability', [dataset], True)