We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6f22b6b commit cb491cdCopy full SHA for cb491cd
maths/abs.py
@@ -5,26 +5,24 @@ def abs_val(num):
5
"""
6
Find the absolute value of a number.
7
8
- >>abs_val(-5)
9
- 5
10
- >>abs_val(0)
+ >>> abs_val(-5.1)
+ 5.1
+ >>> abs_val(-5) == abs_val(5)
11
+ True
12
+ >>> abs_val(0)
13
0
14
15
return -num if num < 0 else num
16
17
-def main():
- """Print absolute value of -34."""
18
- print(abs_val(-34)) # = 34
19
-
20
21
-def testAbs():
+def test_abs_val():
+ """
+ >>> test_abs_val()
22
assert 0 == abs_val(0)
23
24
assert 34 == abs_val(34)
25
26
assert 100000000000 == abs_val(-100000000000)
27
+
28
if __name__ == "__main__":
29
- main()
30
- testAbs()
+ print(abs_val(-34)) # --> 34
0 commit comments