Extra Topic: The Hazards of Float Conditions
Note: extra topics are not in CS Academy, but are required
and can appear on any future
homework, writing session, quiz, or exam.
Failed Example:
x = 0
while x != 1.0:
x += 0.1
print(x) # we never get here!
Fixed Example:
def almostEqual(x, y):
return abs(x - y) < 10**-8
x = 0
while not almostEqual(x, 1.0):
x += 0.1
print(x)