Nested Conditionals MCQ Practice

Question 1 of 10

Library kiosk: overdue true and fines 0.

IF (overdue)
{
  IF (fines > 0)
  {
    DISPLAY ("pay first")
  }
  ELSE
  {
    DISPLAY ("renew online")
  }
}
ELSE
{
  DISPLAY ("checked in")
}

What is displayed?

  1. A. Nothing is displayed.
  2. B. pay first
  3. C. renew online
  4. D. checked in

Question 2 of 10

Which input makes the inner condition unreachable?

IF (speed > 50)
{
  IF (rain)
  {
    DISPLAY ("slow down")
  }
}
ELSE
{
  DISPLAY ("ok")
}
  1. A. speed 80 and rain true
  2. B. speed 60 and rain true
  3. C. speed 55 and rain false
  4. D. speed 40 and rain true

Question 3 of 10

Cafe loyalty: visits 12 and member true.

IF (member)
{
  IF (visits >= 10)
  {
    reward ← 2
  }
  ELSE
  {
    reward ← 1
  }
}
ELSE
{
  reward ← 0
}
DISPLAY (reward)

What is displayed?

  1. A. 2
  2. B. 12
  3. C. 0
  4. D. 1

Question 4 of 10

humidity 80 and windowsOpen false.

IF (humidity > 70)
{
  IF (windowsOpen)
  {
    DISPLAY ("close windows")
  }
  ELSE
  {
    DISPLAY ("run dehumidifier")
  }
}
ELSE
{
  DISPLAY ("comfortable")
}

What is displayed?

  1. A. close windows
  2. B. run dehumidifier
  3. C. comfortable
  4. D. close windowsrun dehumidifier

Question 5 of 10

lives 0 and continues 2.

IF (lives > 0)
{
  IF (continues > 0)
  {
    DISPLAY ("continue?")
  }
  ELSE
  {
    DISPLAY ("game over")
  }
}
ELSE
{
  DISPLAY ("insert coin")
}

What is displayed?

  1. A. continue?
  2. B. game over
  3. C. insert coin
  4. D. Nothing is displayed.

Question 6 of 10

Which statement is always true for this nested structure?

IF (p)
{
  IF (q)
  {
    DISPLAY ("both")
  }
  ELSE
  {
    DISPLAY ("only p")
  }
}
ELSE
{
  DISPLAY ("no p")
}
  1. A. only p displays when q is true and p is false.
  2. B. both displays whenever q is true, even if p is false.
  3. C. If p is false, q is still evaluated before choosing an output.
  4. D. both displays only when p and q are both true.

Question 7 of 10

hours 3 and weekend true.

IF (weekend)
{
  IF (hours <= 2)
  {
    fee ← 3
  }
  ELSE
  {
    fee ← 5
  }
}
ELSE
{
  fee ← 4
}
DISPLAY (fee)

What is displayed?

  1. A. 5
  2. B. 4
  3. C. 2
  4. D. 3

Question 8 of 10

Predict the three outputs in order.

IF (a = true)
{
  IF (c = true)
  {
    DISPLAY ("AC")
  }
  ELSE
  {
    DISPLAY ("A")
  }
}
ELSE
{
  DISPLAY ("none")
}
Trial a c
1 true false
2 false true
3 true true
  1. A. AC, A, none
  2. B. A, none, AC
  3. C. A, AC, none
  4. D. none, A, AC

Question 9 of 10

elevation 1200 and snow true.

IF (elevation >= 1000)
{
  IF (snow)
  {
    DISPLAY ("microspikes")
  }
  ELSE
  {
    DISPLAY ("boots")
  }
}
ELSE
{
  DISPLAY ("trainers")
}

What is displayed?

  1. A. trainers
  2. B. bootsmicrospikes
  3. C. microspikes
  4. D. boots

Question 10 of 10

With x set to 0, what is displayed?

IF (x > 0)
{
  IF (x > 10)
  {
    DISPLAY ("large")
  }
  ELSE
  {
    DISPLAY ("small positive")
  }
}
ELSE
{
  DISPLAY ("nonpositive")
}
  1. A. Nothing is displayed.
  2. B. large
  3. C. small positive
  4. D. nonpositive