wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP Unit 1 Exam

Total questions: 31

Worksheet time: 35mins

Name
Class
Date
1.

What is the primary purpose of defining functions in programming?

a)

To make the code harder to understand.

b)

To debug errors.

c)

To organize and reuse code.

d)

To create loops.

2.

How is a for loop written in Python?

a)

for i in range(4):

b)

loop i in range(4):

c)

repeat i in range(4):

d)

iterate i in range(4):

3.

Which of the following ins NOT a common type of loop in programming?

a)

If Loop

b)

For Loop

c)

While Loop

4.

What is an If statement used for?

a)

To execute code only if a condition is true

b)

To repeat code while a condition is true

c)

To create new variables

d)

To gather information about Karel's world

5.

What does the term "debugging" refer to in programming?

a)

Creating backup copies of code

b)

Identifying and fixing errors in code

c)

Adding new features to a program

d)

Optimizing code for faster execution

6.

What is a run-time error?

a)

A mistake that occurs during the execution of a program

b)

A mistake in the syntax of the code

c)

A mistake in the logic of the code

d)

A mistake that occurs during code compilation

7.

What is pseudocode?

a)

A programming language

b)

A brief explanation of code in plain English

c)

A type of algorithm

d)

A control structure

8.

A while() loop is used to:

a)

Execute a section of code until a condition is met

b)

Wait a specified length of time

c)

Ensure that the battery has enough power for an operation

d)

Check an input repeatedly

9.

What does this code do?

a)

Moves forward 1 time

b)

Moves forward forever

c)

Moves forward 5 times

d)

Moves left

10.

What is a postcondition in a function?

a)

  • What happens before the function is called.

b)

  • What is true after the function is called.

c)

A variable in the function.

d)

The name of the function.

11.

What is the purpose of the if statement in the pseudocode?

a)

To check if the player has won the game.

b)

To check if the player is still alive.

c)

To check if the monster is still alive.

d)

To check if the game is over.

12.

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?

a)

While Loop

b)

Loop-De-Loop

c)

For Loop

d)

Fruit Loop

13.

Debugging is

a)

how characters are arranged in a statement

b)

detecting or removing errors from a program

c)

removing viruses from a computer

d)

the meaning of each of the characters and symbols in the program

14.

What symbol do you use to make a single line comment in Python?

a)

@

b)

¬

c)

;

d)

#

15.

A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly

a)

True

b)

False

16.

Top-down design is a problem-solving approach that involves:

a)

Starting with the smallest subproblems and building up to the larger problem.

b)

Breaking a large problem into smaller, more manageable subproblems.

c)

Using a trial-and-error method to find a solution.

d)

Creating a flowchart to visualize the problem.

17.

Decomposition is a specific technique used within top-down design. Which of the following best describes decomposition?

a)

Translating code from one language to another.

b)

Breaking a complex program into smaller, more manageable parts.

c)

Removing bugs from code.

d)

Combining multiple programs into one.

18.

Why is it important to comment your code?

a)

To create variables.

b)

To make the code more efficient and run faster.

c)

To define new functions to be used within your program.

d)

To explain the code's functionality and improve readability.

19.

Which of the following is an example of abstraction in programming?

a)

Using a function without knowing its internal implementation.

b)

Debugging a program line by line.

c)

Copying and pasting code multiple times.

d)

Writing every step of an algorithm in detail.

20.

What is an algorithm in computer science?

a)

A type of programming language.

b)

A way to store data in memory.

c)

A method for creating graphics in a program.

d)

A step-by-step procedures for solving a problem or accomplishing a task.

21.

What is the correct syntax for a basic 'for' loop in Python?

a)

for (i=0; i<5; i++)

b)

For i=0 to 5:

c)

for i in range (5):

d)

for (in in range (5))

22.

What is the purpose of using an 'if' statement?

a)

To define a new function.

b)

To import external libraries.

c)

To make decisions based on conditions.

d)

To repeat a block of code.

23.

What is the primary difference between a 'while' loop and a 'for' loop?

a)

'For' loops can only be used with strings.

b)

'For' loops are faster than 'While' loops.

c)

'While' loops can only be used with numbers.

d)

'While' loops continue until a condition is false. 'For' loops iterate a specific number of times.

24.

Which of the following ARE basic control structures in programming?
(there may be more than 1 correct answer)

a)

Sequence

b)

Selection

c)

Recursion

d)

Iteration

25.

What type of error occurs when the program runs but produces incorrect results?

a)

Syntax error

b)

Runtime error

c)

Logic error

26.

What is the purpose of the 'def' keyword in Python?

a)

To import a module

b)

To declare a variable

c)

To create a loop

d)

To define a new function

27.

Which of the following is an example of top-down design in programming?

a)

Writing code without planning

b)

Focusing on small details before considering overall structure

c)

Copying code from other projects without modification

d)

Starting with main goals and breaking them into smaller subtasks

28.

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?

a)

b)

c)

d)

29.

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?

a)

b)

c)

d)

30.

What do we call assumptions we make about what must be true before a function is called?

a)

Control Structures

b)

Postcondition

c)

Comment

d)

Precondition

31.

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.

4 lines