Back

Question Set 5

Six questions · 10 minutes · cumulative through 1.23

divider

What This Is

The last set before the exam. Six questions weighted toward procedures, and the whole quarter is fair game.

Set a timer for 10 minutes. On paper, no computer. Mark each answer sure or unsure and then revise whatever the unsure ones point at — that is what this set is for.


The Questions


Question 1

What does this print?

Lua
local function double(n)
local answer = n * 2
end
local result = double(4)
print(result)
  • (A) 8
  • (B) 4
  • (C) nil
  • (D) An error, because the function returns nothing

Question 2

What does this print?

Lua
local count = 10
local function reset(count)
count = 0
return count
end
reset(count)
print(count)
  • (A) 0
  • (B) 10
  • (C) nil
  • (D) An error, because count is used twice

Question 3

In exam notation, a procedure hands a value back with:

  • (A) return expression
  • (B) RETURN(expression)
  • (C) DISPLAY(expression)
  • (D) result ← expression

Question 4

tally([4, 12, 30, 8, 11], 10) returns:

Exam notation
PROCEDURE tally(scores, limit)
{
n ← 0
i ← 1
REPEAT LENGTH(scores) TIMES
{
IF(scores[i] > limit)
{
n ← n + 1
}
i ← i + 1
}
RETURN(n)
}
  • (A) 2
  • (B) 3
  • (C) 5
  • (D) 53

Question 5 — select all that apply

The Create Performance Task requires at least one student-developed procedure. Which of these would count?

  • (A) love.draw, with forty lines you wrote inside it
  • (B) love.keypressed(key), because it has a parameter
  • (C) drawShip(x, y, size), which you wrote and call twice
  • (D) tally(scores, limit), which you wrote and call once

Question 6

What does this print?

Lua
local function total(t)
local sum = 0
for i, v in ipairs(t) do
sum = sum + v
return sum
end
end
print(total({4, 6, 10}))
  • (A) 20
  • (B) 4
  • (C) nil
  • (D) 10

Submit

Six answers with sure or unsure beside each, and your time. For question 5, list every letter you chose.

This is the last set before the exam. Whatever you marked unsure is your revision list, and the four section summaries are where to look.

Worth 4 points, graded on completion.

Start the Timer