Oct-12-2018, 06:37 PM
(This post was last modified: Oct-12-2018, 06:37 PM by PythonZenon.)
Hi everyone.
The post seems long but it won't take much of your time, I promise :)
This is the code:
1. Why is this happening?
2. How to work around/with it?
What I have done is
From both cases I can see that the problem occurs within p + 0.01. Why? What's going on?
Thank you! :)
The post seems long but it won't take much of your time, I promise :)
This is the code:
def frange(start, stop, step): i = start while i <= stop: yield i i += step for p in frange(5, 6.9, 0.01): print(str(p))First few print outputs are:
Output:5
5.01
5.02
5.029999999999999
5.039999999999999
5.049999999999999
5.059999999999999
5.0699999999999985
5.079999999999998
5.089999999999998
5.099999999999998
and all of the rest is the same.1. Why is this happening?
2. How to work around/with it?
What I have done is
def frange(start, stop, step): i = start while i <= stop: i = float("{0:.2f}".format(i)) yield i i += stepand then the print is fine. But that's not my main issue. My main issue happens here:
def gmaxf(d): if d == 13: return 32 if d == 16: return 38 if d == 20: return 40 if d == 25: return 44 if d == 32: return 50 if d == 40: return 56 return 0 def wminf(d): if d == 13: return 5 if d == 16: return 6 if d == 20: return 8 if d == 25: return 10 if d == 32: return 11.5 if d == 40: return 14 return 0 for d in diameters: pmin = wminf(d) pmax = d + 0.09 gmin = d + 0.1 gmax = gmaxf(d) for p in frange(wminf(d), pmax, 0.01): for w in frange(wminf(d), p, 0.01): rmin = rminf(p, w, gmin, gmax) rmax = rmaxf(p, w, gmin, gmax) if rmin > rmax: pmin = p + 0.01 print('D = ' + str(d) + ', Pmin = ' + str(pmin))And this is the output:
Output:D = 13, Pmin = 12.2
D = 16, Pmin = 15.03
D = 20, Pmin = 18.540000000000003
D = 25, Pmin = 23.12
D = 32, Pmin = 30.060000000000002
D = 40, Pmin = 37.669999999999995
As you can see, I'm trying to found out minimum possible value for Pmin. rminf and rmaxf do not in any way change any of the variables' values, they simply calculate something and return it. I don't want to just round-up the value for Pmin because I have no idea what is going on. For example, I can assume that Pmin = 30.06 for D = 32. But what the heck is going on with Pmin for D = 40?From both cases I can see that the problem occurs within p + 0.01. Why? What's going on?
Thank you! :)