I made this script for finding the solution to a puzzle. I had to put the numbers 1 to 9 through some arithmetic to get 66. But for some reason I get a list of approximates that include 68.5333333333, 68.6666666667, 69.6 and so on.
Here is my code (I'd be very grateful for peer review as well if that's ok):
def equation():
# intertools gives me the posibility to permutate a list of numbers, floating points for this case so I have decimals
import itertools
permutationlist = list(itertools.permutations([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0]))
# I make a loop for every permutation, the last number is 9! for the last one
for n in xrange (0,362880):
currentlist = permutationlist[n]
# every variable is taken for each item in the current list
a = currentlist[0]
b = currentlist[1]
c = currentlist[2]
d = currentlist[3]
e = currentlist[4]
f = currentlist[5]
g = currentlist[6]
h = currentlist[7]
i = currentlist[8]
# if statement to pick up what computes to 66
# here is the problem, what part of == is not clear to Python?
if ((((((((((((a+13)*b)//c)+d)+12)*e)-f)-11)+g)*h)//i)-10) == 66:
print ('[%s]+13*[%s]/[%s]+[%s]+12*[%s]-[%s]-11+[%s]*[%s]/[%s]-10 =') % (a,b,c,d,e,f,g,h,i), ((((((((((((a+13)*b)/c)+d)+12)*e)-f)-11)+g)*h)/i)-10)
else:
pass
# next list...
n = n + 1
equation()