T/F: Karel's world is a grid of streets (running East-West) and avenues (running North-South).
Answer: True
Why: This defines the grid system Karel uses for navigation.
The move() command moves Karel one space forward, regardless of which direction it is facing.
Answer: True
Why: The move() command is relative to Karel's current orientation.
T/F: turnRight() is a built-in, default command for the basic Karel.
Answer: False
Why: Karel only knows turnLeft(). You must define the turnRight() function yourself using three turnLeft() commands.
T/F: Defining a function teaches Karel a new word or command.
Answer: True
Why: This is the core purpose of a function—to create a new, reusable command (like turnRight()) from existing ones.
T/F: Code execution in a Karel program always starts with the main() function.
Answer: True
Why: The main() function is the entry point, or starting point, for every program.
T/F: Top-down design involves writing all the small, helper functions first and then combining them into a main() function.
Answer: False
Why: This describes bottom-up design. Top-down design starts with the main goal (in main()) and breaks it down into smaller, high-level functions.
T/F: Comments, marked with //, are ignored by the computer but help humans read and understand the code.
Answer: True
Why: Comments are for human readability and do not affect how the program runs.
SuperKarel and the basic Karel have the exact same built-in commands.
Answer: False
Why: SuperKarel adds turnRight() and turnAround() as built-in commands, so you don't have to define them.
T/F: A for loop is ideal when you want to repeat code, but you don't know exactly how many times.
Answer: False
Why: A for loop is for a specific, known number of repetitions (e.g., "repeat 5 times"). A while loop is used for an unknown number (e.g., "repeat while the front is clear").
T/F: The condition frontIsClear() will be true if there is a wall one step in front of Karel.
Answer: False
Why: It will be false if there is a wall. It is true only if the path is clear.
Which control structure is best for making Karel move forward until it hits a wall?
A) for loop
B) if statement
C) while loop
D) function
Answer: C
Why: This is a task with an unknown number of repetitions. The while (frontIsClear()) loop is the perfect tool, as it stops when the condition (front is clear) becomes false.
What is a common problem with while loops if the condition never becomes false?
A) The program crashes.
B) The program skips the loop.
C) It creates an "infinite loop."
D) It runs the loop only once.
Answer: C
Why: If the condition always stays true, the loop will never stop executing.
What code would make Karel pick up all balls on a single corner, no matter how many there are?
A) if (ballsPresent()) { takeBall(); }
B) for (var i = 0; i < 100; i++) { takeBall(); }
C) while (ballsPresent()) { takeBall(); }
D) takeBall();
Answer: C
Why: The while loop checks "are there balls?", takes one, and repeats this process until ballsPresent() is false (i.e., the corner is empty).
What is a "bug" in programming?
A) An error in the code that causes an unexpected result.
B) A comment that is too long.
C) A program that runs too slowly.
D) A feature that the user doesn't like.
Answer: A
Why: A bug is an error, flaw, or fault in the program's logic or syntax that causes it to behave incorrectly.
What is "Rubber Duck Debugging"?
A) A software tool that automatically finds bugs.
B) Deleting all your code and starting over.
C) Explaining your code, line-by-line, to an inanimate object.
D) Asking a more senior programmer for help.
Answer: C
Why: The act of explaining the code aloud often forces you to see the logical error you missed.
Why is code indentation important?
A) It makes the program run faster.
B) It shows the structure and hierarchy of the code for human readers.
C) It is required by the computer to run the code.
D) It adds colors to the code editor.
Answer: B
Why: Indentation (e.g., inside a loop or function) makes it visually clear which lines of code "belong" to which block.
Which lines of code should be indented?
A) All lines of code.
B) Only comments.
C) Code that is inside a function's curly braces {...} or a control structure's {...}.
D) Only the main() function.
Answer: C
Why: Any code inside a {...} block should be indented one level deeper to show it's part of that block.
What is a "control structure"?
A) A command that controls Karel, like move().
B) A way to structure comments.
C) A programming statement that changes the flow of execution (like if, for, while).
D) A way to name a function.
Answer: C
Why: Control structures "control" which line of code is executed next, allowing for loops and conditional paths instead of just a top-to-bottom list.
What is it called when you place one loop inside of another loop?
A) A broken loop
B) A nested loop
C) An infinite loop
D) A super loop
Answer: B
Why: Just like a bird's "nest," one loop is placed inside the other, allowing you to iterate over rows and columns, for example.
What is a "postcondition" comment?
A) A comment that states what will be true after a function runs.
B) A comment that states what must be true before a function runs.
C) A comment written after the project is finished.
D) A comment that describes what the function does.
Answer: A
Why: A postcondition is a condition that is guaranteed to be true post- (after) the function has run (assuming the preconditions were met).
If Karel is facing East and runs a turnAround() function (defined as turnLeft(); turnLeft();), which way will Karel be facing?
A) North
B) South
C) East
D) West
Answer: D
Why: Two 90-degree left turns equal a 180-degree turn, making Karel face the opposite direction (West).
What is an "off-by-one" error?
A) An error where the code won't run.
B) An error where a loop runs one too many or one too few times.
C) An error where Karel is on the wrong street.
D) An error where you forget a semicolon.
Answer: B
Why: This is a common bug with for loops, e.g., using i <= 10 (runs 11 times) when you meant i < 10 (runs 10 times).
Which condition would you use in a while loop to make Karel move forward until it finds a tennis ball?
A) while (ballsPresent()) { move(); }
B) while (noBallsPresent()) { move(); }
C) while (frontIsClear()) { move(); }
D) while (facingNorth()) { move(); }
Answer: B
Why: The loop should run while there are no balls. It will stop as soon as noBallsPresent() is false, which means ballsPresent() has become true.
Which of these will cause an error and stop the program (an "error beep")?
A) Calling move() when facing a wall.
B) Calling takeBall() on a corner with no balls.
C) Calling putBall() on a corner that already has balls.
D) Both A and B.
Answer: D
Why: Both A (running into a wall) and B (picking up a non-existent ball) are invalid actions that crash the program. C is perfectly valid.
The proper structure for defining a function named go is:
A) function go() { ... }
B) go(); { ... }
C) function go; { ... }
D) go() = { ... }
A) function go() { ... }
Why: The syntax is the keyword function, the name go, parentheses (), and the body of the function inside curly braces {...}.