Conditionals MCQ Practice

Question 1 of 10

What is displayed when temp is 32?

IF (temp < 32)
{
  DISPLAY ("freeze")
}
ELSE
{
  DISPLAY ("safe")
}
  1. A. safe
  2. B. 32
  3. C. Nothing is displayed.
  4. D. freeze

Question 2 of 10

For score = 90, what is displayed?

IF (score >= 90)
{
  DISPLAY ("pass")
}
ELSE
{
  DISPLAY ("retry")
}
  1. A. passretry
  2. B. pass
  3. C. retry
  4. D. 90

Question 3 of 10

A shipping rule uses weight. Both branches look useful. For weight = 10, what is displayed?

IF (weight <= 10)
{
  DISPLAY ("standard box")
}
ELSE
{
  DISPLAY ("large box")
}
  1. A. standard boxlarge box
  2. B. Nothing is displayed.
  3. C. standard box
  4. D. large box

Question 4 of 10

Which value of n causes the ELSE branch to run?

IF (n > 5)
{
  DISPLAY ("above")
}
ELSE
{
  DISPLAY ("not above")
}
  1. A. 8
  2. B. 6
  3. C. 10
  4. D. 5

Question 5 of 10

Trace with balance = 50.

IF (balance < 50)
{
  fee ← 5
}
ELSE
{
  fee ← 0
}
DISPLAY (fee)

What is displayed?

  1. A. 0
  2. B. 50
  3. C. 45
  4. D. 5

Question 6 of 10

age is 17. What is displayed?

IF (age >= 18)
{
  DISPLAY ("adult")
}
ELSE
{
  DISPLAY ("minor")
}
  1. A. adult
  2. B. minor
  3. C. 17
  4. D. adultminor

Question 7 of 10

For x = 0, which message appears?

IF (x = 0)
{
  DISPLAY ("zero")
}
ELSE
{
  DISPLAY ("nonzero")
}
  1. A. 0
  2. B. Nothing is displayed.
  3. C. zero
  4. D. nonzero

Question 8 of 10

A thermostat uses the segment below with reading = 72. Both displayed phrases sound reasonable for a home. What actually displays?

IF (reading > 72)
{
  DISPLAY ("cool the room")
}
ELSE
{
  DISPLAY ("leave as is")
}
  1. A. cool the roomleave as is
  2. B. 72
  3. C. cool the room
  4. D. leave as is

Question 9 of 10

points is 100. What is grade after the segment?

IF (points > 100)
{
  grade ← "error"
}
ELSE
{
  grade ← "ok"
}
  1. A. ok
  2. B. 100
  3. C. points
  4. D. error

Question 10 of 10

Which input makes "below" display?

IF (speed >= 60)
{
  DISPLAY ("at or above")
}
ELSE
{
  DISPLAY ("below")
}
  1. A. 100
  2. B. 59
  3. C. 60
  4. D. 61