Problem 128020 · easy · Phase 01 Prerequisites & Setup

Sign of a Number

conditionals · functions · return

From now on you will write functions instead of whole programs. A function takes inputs (called parameters), does some work, and hands back an answer with return. The tests call your function with different inputs and check what comes back.

Write a function sign(n) that takes an integer n and returns one of three strings:

  • "positive" if n is greater than 0
  • "negative" if n is less than 0
  • "zero" if n is exactly 0

Examples

Input:  n = 5
Output: "positive"
Input:  n = -3
Output: "negative"
Input:  n = 0
Output: "zero"

Constraints

  • -10**9 <= n <= 10**9
  • Return the string; do not print it.

Goals

  • Define a function with def and give a result back with return
  • Choose between three outcomes with if, elif and else
  • Compare numbers with > < and ==
Starting Python…