from __future__ import division #Only necessary for python 2
a= 1 #start with 1
b = 1
goal = 1.4142 #this is what we want
fraction = round(a/b,4) #this is how we want to achieve our goal
while fraction != goal : #If the fraction equals our goal we are happy
if fraction > goal: #If we surpassed our goal, we might need a bigger denominator
a = 1 #reset the numerator
b = b +1 #increase the denominator
else :
a = a +1 #just increase the numerator
fraction = round(a/b,4) #evaluate our current values
print('Iterationstep: ' +str(a) +' / ' +str(b) + ' equals ' + str(fraction)) #Just to see what is going on
print('We achieved the result! :' +str(a) +' / ' +str(b) + ' equals ' +str(goal)) #Hooray