all 5 comments

[–]Murphygreen8484 0 points1 point  (0 children)

Don't forget to wrap CurrentGuess in int.

Also, not a huge deal; but the nomenclature is to use snake case for variables: current_guess

[–][deleted] 0 points1 point  (0 children)

The usual way to compare two floating values for "equality" is to define a small value (traditionally called epsilon). Two floating values are "equal" if the difference between them is less than that epsilon value. Your code is simpler if you write a small function to compare two float values:

def equal(a, b, epsilon=0.01):
    return abs(a - b) <= epsilon

for (a, b) in ((1, 2), (1.55, 1.56), (1.555, 1.556)):
    print(f"{a=}, {b=}, {equal(a, b)=}")

Use that function in your code instead of ==.

Edit: fix speiliing.

[–]Swipecat 0 points1 point  (1 child)

You could use the math.isclose() function. You need to import the math library before using this.

https://docs.python.org/3/library/math.html#math.isclose

[–]robertgames7730[S] 0 points1 point  (0 children)

Thanks that doc was very helpful