File tree Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Original file line number Diff line number Diff line change 2
2
This module shows how to create new integers by applying math expressions
3
3
on existing integers.
4
4
"""
5
+ import math
5
6
6
7
7
8
def main ():
@@ -19,7 +20,7 @@ def main():
19
20
# Division is tricky because Python 3.x returns 0.5 of type `float`
20
21
# whereas Python 2.x returns 0 of type `int`. If this line fails, it
21
22
# 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 )
23
24
24
25
# If an integer division is desired, then an extra slash must be
25
26
# added to the expression. In Python 2.x and Python 3.x, the behavior
Original file line number Diff line number Diff line change 3
3
a program. This module shows how to define variables and make assertions
4
4
about the state of each defined variable.
5
5
"""
6
+ import math
6
7
7
8
8
9
def main ():
@@ -47,7 +48,7 @@ def main():
47
48
# integer literals
48
49
assert 10_000 == 10000
49
50
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 )
51
52
52
53
# There is also a special literal called None. This literal is used to
53
54
# point that a particular variable or object is not created
You can’t perform that action at this time.
0 commit comments