Categorize number

Write a Python function that takes an integer as input and returns:

  • “Positive” if it’s positive,
  • “Negative” if it’s negative, and
  • “Zero” if it’s zero,

using only if statements.

Complete Listing 1. Save the completed code as categorize_number.py and run it to check the supplied assertions.

Listing 1: Starter function and checks for categorize_number.
def categorize_number(num: int) -> str:
    raise NotImplementedError("Replace this line with your code.")


# Above zero
got = categorize_number(5)
assert got == "Positive", f"5: expected 'Positive', got {got!r}"

# Below zero
got = categorize_number(-3)
assert got == "Negative", f"-3: expected 'Negative', got {got!r}"

# Zero itself, which belongs to neither of the other two
got = categorize_number(0)
assert got == "Zero", f"0: expected 'Zero', got {got!r}"

# One either side of zero
got = categorize_number(1)
assert got == "Positive", f"1: expected 'Positive', got {got!r}"

got = categorize_number(-1)
assert got == "Negative", f"-1: expected 'Negative', got {got!r}"

# Your case: which number is most likely to break it?
# got = categorize_number(___)
# assert got == "___", f"___: expected '___', got {got!r}"
  • assert condition checks a Boolean condition. A true condition produces no output; a false condition raises AssertionError. For example, assert 2 + 3 == 5 passes.