pythonbeginner10 minutes

Predict the Output of a Simple Number Check Function

Analyze a Python function that checks if a number is positive, negative, or zero, and predict its output for given inputs.

Challenge prompt

Below is a Python function that takes a number as input and returns a string indicating if the number is positive, negative, or zero. Predict the output of the function calls for the numbers: 10, -5, and 0.

Guidance

  • Read through the function to understand how it classifies numbers based on conditions.
  • Trace the function's behavior for each input to determine the return value.

Hints

  • Remember that zero is neither positive nor negative.
  • Check the order of the if, elif, and else conditions carefully.

Starter code

def check_number(num):
    if num > 0:
        return "Positive"
    elif num < 0:
        return "Negative"
    else:
        return "Zero"

print(check_number(10))
print(check_number(-5))
print(check_number(0))

Expected output

Positive Negative Zero

Core concepts

conditionalsfunctions

Challenge a Friend

Send this duel to someone else and see if they can solve it.