Nested Conditionals MCQ Practice

Question 1 of 10

A ticket booth runs this segment. The variable age is 16.

IF (age >= 18)
{
  IF (age >= 65)
  {
    DISPLAY ("senior")
  }
  ELSE
  {
    DISPLAY ("adult")
  }
}
ELSE
{
  DISPLAY ("youth")
}

What is displayed?

  1. A. youth
  2. B. Nothing is displayed.
  3. C. senior
  4. D. adult

Question 2 of 10

A weather app uses nested conditionals. temp is 72 and raining is false.

IF (temp > 60)
{
  IF (raining)
  {
    DISPLAY ("bring umbrella")
  }
  ELSE
  {
    DISPLAY ("warm walk")
  }
}
ELSE
{
  DISPLAY ("stay inside")
}

What is displayed?

  1. A. bring umbrella
  2. B. warm walk
  3. C. stay inside
  4. D. warm walkstay inside

Question 3 of 10

Consider this segment with score set to 55.

IF (score >= 70)
{
  IF (score >= 90)
  {
    result ← "honor"
  }
  ELSE
  {
    result ← "pass"
  }
}
ELSE
{
  result ← "retry"
}
DISPLAY (result)

What is displayed?

  1. A. honor
  2. B. pass
  3. C. retry
  4. D. 55

Question 4 of 10

A locker opens only when both tests succeed. pinCorrect is true and doorClosed is false.

IF (pinCorrect)
{
  IF (doorClosed)
  {
    DISPLAY ("open")
  }
  ELSE
  {
    DISPLAY ("close door first")
  }
}
ELSE
{
  DISPLAY ("wrong pin")
}

What is displayed?

  1. A. wrong pin
  2. B. Nothing is displayed.
  3. C. open
  4. D. close door first

Question 5 of 10

Which statement is true when x is 10?

IF (x > 20)
{
  IF (x > 5)
  {
    DISPLAY ("inner")
  }
}
  1. A. inner is not displayed because the outer test fails, so the inner test is never reached.
  2. B. inner is displayed because both tests would be true if evaluated.
  3. C. An error occurs because the inner test contradicts the outer test.
  4. D. inner is displayed because x > 5 is true.

Question 6 of 10

A museum ticket printer uses this segment with dayType weekend and age 9.

IF (dayType = "weekend")
{
  IF (age < 12)
  {
    price ← 8
  }
  ELSE
  {
    price ← 14
  }
}
ELSE
{
  price ← 10
}
DISPLAY (price)

What is displayed?

  1. A. 9
  2. B. 8
  3. C. 14
  4. D. 10

Question 7 of 10

The table shows three input pairs. The segment is:

IF (a > 0)
{
  IF (b > 0)
  {
    DISPLAY ("Q1")
  }
  ELSE
  {
    DISPLAY ("Q4")
  }
}
ELSE
{
  DISPLAY ("left")
}
a b Output
3 2 ?
-1 5 ?
4 -2 ?

Which outputs match top to bottom?

  1. A. Q4, left, Q1
  2. B. Q1, Q4, left
  3. C. Q1, left, Q4
  4. D. left, Q1, Q4

Question 8 of 10

A delivery app runs this with weight 12 and fragile true.

IF (weight <= 20)
{
  IF (fragile)
  {
    DISPLAY ("padded box")
  }
  ELSE
  {
    DISPLAY ("standard box")
  }
}
ELSE
{
  DISPLAY ("freight")
}

What is displayed?

  1. A. standard box
  2. B. freight
  3. C. padded boxfreight
  4. D. padded box

Question 9 of 10

For which value of n does the inner DISPLAY never execute?

IF (n >= 10)
{
  IF (n MOD 2 = 0)
  {
    DISPLAY ("even ten-plus")
  }
}
  1. A. 8
  2. B. 10
  3. C. 12
  4. D. 11

Question 10 of 10

A quiz grader uses nested IFs with points 92 and late false.

IF (points >= 90)
{
  IF (late)
  {
    grade ← "A-"
  }
  ELSE
  {
    grade ← "A"
  }
}
ELSE
{
  grade ← "B or below"
}
DISPLAY (grade)

What is displayed?

  1. A. A-
  2. B. A
  3. C. B or below
  4. D. 92