easy +5 pts

Sign of a number

Implement a function that returns -1, 0, or 1 based on the sign of the number.

Write a function `sign_of_number(n)` that takes a single number `n` (integer or float) and returns: - `-1` if `n` is negative, - `0` if `n` is zero, - `1` if `n` is positive. Do not use any imports. The function should handle both integers and floats, including negative zero if you encounter it (consider `-0.0` as zero).

Constraints

Input can be any integer or float. The function must return an integer: one of -1, 0, or 1.

Example

>>> sign_of_number(5)
1
>>> sign_of_number(-3.5)
-1
>>> sign_of_number(0)
0
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use comparison operators directly: `n > 0`, `n < 0`, and `n == 0`.
Remember that in Python, `-0.0 == 0` is True, so you can check `n == 0` first or use `n > 0` and `n < 0`.
Order your checks carefully: what should be returned for `n = -0.0`?
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.