Bird
0
0

You want to print 'Positive even', 'Positive odd', or 'Zero or negative' based on a number using nested conditionals. Which code correctly implements this?

hard📝 Application Q8 of 15
Python - Conditional Statements
You want to print 'Positive even', 'Positive odd', or 'Zero or negative' based on a number using nested conditionals. Which code correctly implements this?
num = 4
# Choose correct code:
Aif num > 0: if num % 2 == 0: print('Positive odd') else: print('Positive even') else: print('Zero or negative')
Bif num > 0: if num % 2 == 1: print('Positive even') else: print('Positive odd') else: print('Zero or negative')
Cif num >= 0: if num % 2 == 0: print('Positive even') else: print('Positive odd') else: print('Zero or negative')
Dif num > 0: if num % 2 == 0: print('Positive even') else: print('Positive odd') else: print('Zero or negative')
Step-by-Step Solution
Solution:
  1. Step 1: Check outer condition

    Number must be greater than zero to be positive.
  2. Step 2: Check inner condition

    Even numbers have remainder 0 when divided by 2.
  3. Step 3: Verify else block

    Print 'Zero or negative' if number is not positive.
  4. Final Answer:

    if num > 0: if num % 2 == 0: print('Positive even') else: print('Positive odd') else: print('Zero or negative') correctly implements the logic.
  5. Quick Check:

    Use remainder 0 for even check [OK]
Quick Trick: Check positivity first, then evenness [OK]
Common Mistakes:
MISTAKES
  • Using wrong modulo condition for even/odd
  • Checking >= 0 instead of > 0 for positivity
  • Swapping print statements for even and odd

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes