8000 Fix float comparison solution (#229) · fabioacl/python-tutorial@e419b84 · GitHub
[go: up one dir, main page]

Skip to content

Commit e419b84

Browse files
authored
Fix float comparison solution (empa-scientific-it#229)
1 parent 89d465e commit e419b84

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

basic_datatypes.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@
646646
},
647647
"outputs": [],
648648
"source": [
649+
"import math\n",
650+
"\n",
649651
"a = 0.1 + 0.2\n",
650652
"b = 0.3\n",
651653
"print(f\"Is {a} equal to {b}? {a == b}\")\n",
@@ -2203,7 +2205,6 @@
22032205
]
22042206
},
22052207
{
2206-
"attachments": {},
22072208
"cell_type": "markdown",
22082209
"metadata": {},
22092210
"source": [
@@ -2739,7 +2740,7 @@
27392740
"name": "python",
27402741
"nbconvert_exporter": "python",
27412742
"pygments_lexer": "ipython3",
2742-
"version": "3.10.13"
2743+
"version": "3.11.1"
27432744
},
27442745
"vscode": {
27452746
"interpreter": {

tutorial/tests/test_basic_datatypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_quadratic_equation(
9090

9191

9292
def reference_a_plus_b_equals_c(a: float, b: float, c: float) -> bool:
93-
return a + b == c
93+
return math.isclose(a + b, c)
9494

9595

9696
@pytest.mark.parametrize(
@@ -103,6 +103,7 @@ def reference_a_plus_b_equals_c(a: float, b: float, c: float) -> bool:
103103
(23.1, 1.8, 14.2),
104104
(-10.5, 7.4, 84),
105105
(1e-5, 3.5e-5, 2.5),
106+
(0.1, 0.2, 0.3),
106107
],
107108
)
108109
def test_a_plus_b_equals_c(

0 commit comments

Comments
 (0)
0