Download LESSONS 1-20 -CODEHS KAREL PROGRAMMING EXAM and more Exams Computer Science in PDF only on Docsity!
LESSONS 1- 20 - CODEHS KAREL PROGRAMMING
EXAM QUESTIONS WITH DETAILED- VERIFIED
ANSWERS- ALREADY GRADED A+ || NEWLY
RELEASED
Computer science / programming language Examination Summary:- Section Topics Covered Questions 1 Karel Commands and Basic Syntax 1 – 25 2 Functions and Top-Down Design 26 – 50 3 For Loops 51 – 70 4 While Loops 71 – 85 5 If Statements and If/Else Statements 86 – 105 6 Control Structures and Problem-Solving 106 – 125 7 Debugging, Testing, and Good Programming Style 126 – 140 8 Advanced Karel Concepts and Challenges 141 – 150
Section 1: Karel Commands and Basic Syntax (Questions 1 –
- Which of the following is a valid Karel command? A. move; B. MOVE C. move(); D. move() CORRECT ANSWER : C. move(); ✅ RATIONALE : Karel commands are case‑sensitive and must end with parentheses (). The correct syntax is move();. Commands cannot have spaces, and capitalization must match exactly.
- Which command does Karel use to place a tennis ball at its current location? A. addBall(); B. placeBall(); C. putBall();
A. turn left(); B. turnLeft(); C. TurnLeft(); D. turnLeft(); CORRECT ANSWER : B. turnLeft(); ✅ RATIONALE : Karel commands are case‑sensitive and cannot contain spaces. turnLeft(); is the correct syntax.
- What command does Karel use to move forward one space? A. move(); B. Move(); C. forward(); D. go(); CORRECT ANSWER : A. move(); ✅ RATIONALE : move(); is the Karel command that moves Karel forward one space in the direction it is facing.
- By default, Karel knows how to turn right. A. True B. False CORRECT ANSWER : B. False ✅ RATIONALE : Karel does not know how to turn right by default. Programmers must teach Karel to turn right by defining a function or using three turnLeft(); commands.
- If Karel is currently facing North and the code turnLeft(); turnLeft(); runs, which direction is Karel facing now? A. North B. South C. East D. West CORRECT ANSWER : B. South ✅
CORRECT ANSWER : B. Functions ✅ RATIONALE : Functions allow programmers to teach Karel new commands, such as turnRight();, by combining existing commands.
- What is the name of the function that is automatically called when you click "Run" in a Karel program? A. main(); B. start(); C. run(); D. begin(); CORRECT ANSWER : B. start(); ✅ RATIONALE : The start(); function is automatically called when you click Run. It should be the first function defined in your program.
- How many times should the start() function be defined in a Karel program?
A. 0
B. 1
C. 2
D. However many you like CORRECT ANSWER : B. 1 ✅ RATIONALE : The start(); function should be defined exactly once in a program. It is the entry point for Karel's execution.
- How many times should the start() function be called in a Karel program? A. 0 B. 1 C. 2 D. However many times you like CORRECT ANSWER : A. 0 ✅
D. Corner CORRECT ANSWER : A. Row ✅ RATIONALE : In Karel's world, rows are called streets, and columns are called avenues.
- What is an avenue in a Karel world? A. Row B. Column C. Street D. Corner CORRECT ANSWER : B. Column ✅ RATIONALE : In Karel's world, columns are called avenues, and rows are called streets.
- Karel starts at Street 1, Avenue 1, facing East in a 5× world. What will happen after this code runs? move(); move(); turnLeft(); move();
A. Karel will be at Street 2, Avenue 3 B. Karel will be at Street 1, Avenue 3 C. Karel will crash into a wall D. Karel will turn around CORRECT ANSWER : C. Karel will crash into a wall ✅ RATIONALE : Starting at (1,1) facing East, Karel moves to (1,2), then (1,3), then turns left to face North, then attempts to move to Street 2, Avenue 3. In a 5×5 world, this is valid. However, if the world has a wall at the top, Karel may crash. The CORRECT ANSWER depends on the specific world setup.
- If Karel starts at Street 1, Avenue 3 facing East, what street and avenue will Karel be on after this code runs? move(); move(); move(); turnLeft(); move(); A. Street 1, Avenue 6 B. Street 2, Avenue 6 C. Street 2, Avenue 3 D. Street 1, Avenue 4
- Which of the following is NOT true about a Karel command? A. Command names can only be made up of one word B. Commands do not have any spaces C. Capitalization has to match exactly D. Every command ends in (); CORRECT ANSWER : A. Command names can only be made up of one word ✅ RATIONALE : Command names can be made up of multiple words (e.g., turnLeft(); has two words combined). However, they cannot have spaces.
- All commands must be inside of a function. A. True B. False CORRECT ANSWER : A. True ✅
RATIONALE : In Karel programming, all commands must be placed inside a function (such as start(); or a custom function). Commands cannot exist outside of functions.
- What happens when Karel executes putBall(); at a location that already has a ball? A. Karel places an additional ball B. Karel ignores the command C. Karel crashes D. Karel removes the ball CORRECT ANSWER : A. Karel places an additional ball ✅ RATIONALE : Karel can place multiple balls at the same location. putBall(); simply adds another ball.
- What is the correct syntax to call a custom function named buildTower();? A. buildTower; B. buildTower();
- What does Karel do when it executes turnLeft(); while facing East? A. Faces North B. Faces South C. Faces West D. Faces East CORRECT ANSWER : A. Faces North ✅ RATIONALE : Turning left from East rotates Karel 90 degrees counter‑clockwise to North.
- What does Karel do when it executes turnLeft(); while facing West? A. Faces North B. Faces South C. Faces East D. Faces West CORRECT ANSWER : B. Faces South ✅
RATIONALE : Turning left from West rotates Karel 90 degrees counter‑clockwise to South. Section 2: Functions and Top-Down Design (Questions 26 – 50)
- What is a function in Karel programming? A. A way to store data B. A way to teach Karel a new word C. A variable that stores a number D. A loop that repeats code CORRECT ANSWER : B. A way to teach Karel a new word ✅ RATIONALE : Functions allow programmers to teach Karel new commands by defining a sequence of existing commands.
- Why do we use functions in programming? A. Break down our program into smaller parts B. Avoid repeating code
RATIONALE : Top‑down design is a problem‑solving approach that breaks a large problem into smaller, manageable subproblems.
- What is a code comment? A. A way to teach Karel a new word B. A way to give notes to the reader to explain what your code is doing C. A message to your teacher in code D. A place to write whatever you want in your code CORRECT ANSWER : B. A way to give notes to the reader to explain what your code is doing ✅ RATIONALE : Comments are notes in the code that explain what the code does. They are ignored by the computer.
- What is the correct syntax for a single‑line comment in JavaScript? A. // This is a comment
B. /* This is a comment / C. # This is a comment D. CORRECT ANSWER : A. // This is a comment ✅ RATIONALE : In JavaScript, single‑line comments begin with //. Multi‑line comments use / */.
- Why should a programmer indent their code? A. Helps show the structure of the code B. Easier for other people to understand C. Indenting is a key part of good programming style D. All of the above CORRECT ANSWER : D. All of the above ✅ RATIONALE : Indentation improves code readability and shows the structure of functions, loops, and conditionals.