Skip to content

Commit 0c7bc1b

Browse files
committed
Use math.isclose in other modules
1 parent 802d667 commit 0c7bc1b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

ultimatepython/syntax/expression.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module shows how to create new integers by applying math expressions
33
on existing integers.
44
"""
5+
import math
56

67

78
def main():
@@ -19,7 +20,7 @@ def main():
1920
# Division is tricky because Python 3.x returns 0.5 of type `float`
2021
# whereas Python 2.x returns 0 of type `int`. If this line fails, it
2122
# is a sign that the wrong version of Python was used
22-
assert x / 2 == 0.5
23+
assert math.isclose(x / 2, 0.5)
2324

2425
# If an integer division is desired, then an extra slash must be
2526
# added to the expression. In Python 2.x and Python 3.x, the behavior

ultimatepython/syntax/variable.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
a program. This module shows how to define variables and make assertions
44
about the state of each defined variable.
55
"""
6+
import math
67

78

89
def main():
@@ -47,7 +48,7 @@ def main():
4748
# integer literals
4849
assert 10_000 == 10000
4950
assert 0x01_0F_2C == 69_420
50-
assert 3.456_290e-1 == 0.3_456_290
51+
assert math.isclose(3.456_290e-1, 0.3_456_290)
5152

5253
# There is also a special literal called None. This literal is used to
5354
# point that a particular variable or object is not created

0 commit comments

Comments
 (0)