Font size
WorksheetsAP CSP Unit 1 Exam
Total questions: 31
Worksheet time: 35mins
What is the primary purpose of defining functions in programming?
To make the code harder to understand.
To debug errors.
To organize and reuse code.
To create loops.
How is a for loop written in Python?
for i in range(4):
loop i in range(4):
repeat i in range(4):
iterate i in range(4):
Which of the following ins NOT a common type of loop in programming?
If Loop
For Loop
While Loop
What is an If statement used for?
To execute code only if a condition is true
To repeat code while a condition is true
To create new variables
To gather information about Karel's world
What does the term "debugging" refer to in programming?
Creating backup copies of code
Identifying and fixing errors in code
Adding new features to a program
Optimizing code for faster execution
What is a run-time error?
A mistake that occurs during the execution of a program
A mistake in the syntax of the code
A mistake in the logic of the code
A mistake that occurs during code compilation
What is pseudocode?
A programming language
A brief explanation of code in plain English
A type of algorithm
A control structure
A while() loop is used to:
Execute a section of code until a condition is met
Wait a specified length of time
Ensure that the battery has enough power for an operation
Check an input repeatedly
What does this code do?
Moves forward 1 time
Moves forward forever
Moves forward 5 times
Moves left
What is a postcondition in a function?
What happens before the function is called.
What is true after the function is called.
A variable in the function.
The name of the function.
What is the purpose of the if statement in the pseudocode?
To check if the player has won the game.
To check if the player is still alive.
To check if the monster is still alive.
To check if the game is over.
A train company is designing a program to handle passenger complaints. Part of the design is shown in a flowchart.
What type of loop is used in this design?
While Loop
Loop-De-Loop
For Loop
Fruit Loop
Debugging is
how characters are arranged in a statement
detecting or removing errors from a program
removing viruses from a computer
the meaning of each of the characters and symbols in the program
What symbol do you use to make a single line comment in Python?
@
¬
;
#
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
True
False
Top-down design is a problem-solving approach that involves:
Starting with the smallest subproblems and building up to the larger problem.
Breaking a large problem into smaller, more manageable subproblems.
Using a trial-and-error method to find a solution.
Creating a flowchart to visualize the problem.
Decomposition is a specific technique used within top-down design. Which of the following best describes decomposition?
Translating code from one language to another.
Breaking a complex program into smaller, more manageable parts.
Removing bugs from code.
Combining multiple programs into one.
Why is it important to comment your code?
To create variables.
To make the code more efficient and run faster.
To define new functions to be used within your program.
To explain the code's functionality and improve readability.
Which of the following is an example of abstraction in programming?
Using a function without knowing its internal implementation.
Debugging a program line by line.
Copying and pasting code multiple times.
Writing every step of an algorithm in detail.
What is an algorithm in computer science?
A type of programming language.
A way to store data in memory.
A method for creating graphics in a program.
A step-by-step procedures for solving a problem or accomplishing a task.
What is the correct syntax for a basic 'for' loop in Python?
for (i=0; i<5; i++)
For i=0 to 5:
for i in range (5):
for (in in range (5))
What is the purpose of using an 'if' statement?
To define a new function.
To import external libraries.
To make decisions based on conditions.
To repeat a block of code.
What is the primary difference between a 'while' loop and a 'for' loop?
'For' loops can only be used with strings.
'For' loops are faster than 'While' loops.
'While' loops can only be used with numbers.
'While' loops continue until a condition is false. 'For' loops iterate a specific number of times.
Which of the following ARE basic control structures in programming?
(there may be more than 1 correct answer)
Sequence
Selection
Recursion
Iteration
What type of error occurs when the program runs but produces incorrect results?
Syntax error
Runtime error
Logic error
What is the purpose of the 'def' keyword in Python?
To import a module
To declare a variable
To create a loop
To define a new function
Which of the following is an example of top-down design in programming?
Writing code without planning
Focusing on small details before considering overall structure
Copying code from other projects without modification
Starting with main goals and breaking them into smaller subtasks
This question uses a robot in a grid of squares. The robot is represented by a triangle that is initially facing right.
Consider the TWO procedures (also called functions!) in gray.
Which of the following code segments will get the robot to the gray square?
An algorithm is intended to display the output:
red red blue red red blue red red blue
Which of the following code segments can be used to display the intended output?
What do we call assumptions we make about what must be true before a function is called?
Control Structures
Postcondition
Comment
Precondition
Karel is at the park and wants to go down the slide! For this exercise, just get Karel to the top of the steps. You must use at least one function and a for loop.
