Bird
0
0

What will this code print?

medium📝 Predict Output Q5 of 15
Python - Basics and Execution Environment
What will this code print?
def check(num):
    if num > 0:
        print('Positive')
    else:
        print('Non-positive')

check(-1)
APositive
BNon-positive
CNo output
DError due to indentation
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the function call

    The function check is called with -1, which is not greater than 0.
  2. Step 2: Follow the if-else logic

    Since -1 is not > 0, the else block runs, printing 'Non-positive'.
  3. Final Answer:

    Non-positive -> Option B
  4. Quick Check:

    Indentation defines if-else blocks correctly [OK]
Quick Trick: Indent else at same level as if [OK]
Common Mistakes:
MISTAKES
  • Misreading the condition
  • Confusing indentation of else
  • Expecting no output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes