Applies signum function on the number Custom test cases: >>> signum(-10) -1 >>> signum(10) 1 >>> signum(0) 0 >>> signum(-20.5) -1 >>> signum(20.5) 1 >>> signum(-1e-6) -1 >>> signum(1e-6) 1 >>> signum("Hello") Traceback (most r
(num: float)
| 4 | |
| 5 | |
| 6 | def signum(num: float) -> int: |
| 7 | """ |
| 8 | Applies signum function on the number |
| 9 | |
| 10 | Custom test cases: |
| 11 | >>> signum(-10) |
| 12 | -1 |
| 13 | >>> signum(10) |
| 14 | 1 |
| 15 | >>> signum(0) |
| 16 | 0 |
| 17 | >>> signum(-20.5) |
| 18 | -1 |
| 19 | >>> signum(20.5) |
| 20 | 1 |
| 21 | >>> signum(-1e-6) |
| 22 | -1 |
| 23 | >>> signum(1e-6) |
| 24 | 1 |
| 25 | >>> signum("Hello") |
| 26 | Traceback (most recent call last): |
| 27 | ... |
| 28 | TypeError: '<' not supported between instances of 'str' and 'int' |
| 29 | >>> signum([]) |
| 30 | Traceback (most recent call last): |
| 31 | ... |
| 32 | TypeError: '<' not supported between instances of 'list' and 'int' |
| 33 | """ |
| 34 | if num < 0: |
| 35 | return -1 |
| 36 | return 1 if num else 0 |
| 37 | |
| 38 | |
| 39 | def test_signum() -> None: |
no outgoing calls