Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Unit 4 Assessment Review

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the last thing printed by the following program?

a)

10

b)

20

c)

30

d)

60

2.

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?

a)

For Loop

b)

While Loop

c)

Loop and a half

d)

Infinite Loop

3.

How many times will the following program print "hello"?

a)

10

b)

11

c)

9

d)

This code will loop infinitely

4.

The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem.

Which of the following will fix this program?

a)

Change the True in line 3 to be password != SECRET_PASSWORD so that the program doesn’t loop infinitely

b)

Change the True in line 3 to be password == SECRET_PASSWORD so that the program doesn’t loop infinitely

c)

Add a break; statement after line 6 so that the program doesn’t loop infinitely

d)

Put line 7 inside of an else statement

5.

What will the following program print when run?

a)

4

5

4

5

b)

6

5

4

6

5

4

c)

0

2

6

4

d)

6

5

6

5

6.

What is the value of the boolean variable can_vote at the end of this program?

a)

True

b)

False

c)

Yes

d)

none, there is a syntax error in this code

7.

What will be the output of this program?

a)

0

b)

5

c)

True

d)

Nothing will print

8.

What will be the output of this program?

a)

0

b)

5

c)

True

d)

Nothing will print

9.

What is printed by the following program?

a)

Is it warm: True

b)

Is it warm: False

c)

Is it warm: yes

d)

Is it warm: no

10.

What is printed by the following program?

a)

Hello, we are open! Sincerely, the grocery store

b)

Sorry, we are closed!

Sincerely, the grocery store

c)

Hello, we are open!

d)

Sorry, we are closed!

e)

Sincerely, the grocery store

11.

What will the following program print when run?

a)

Issue Driver’s License

b)

Almost eligible for Driver’s License

c)

No requirements met.

d)

Nothing will print

12.

What will the following program print when run?

a)

1

b)

1

3

5

c)

1

4

d)

1

4

5

13.

We want to print the phrase “CodeHS is the best” exactly 25 times. What kind of control structure should we use?

a)

If Statement

b)

While Loop

c)

Break Statement

d)

For Loop

14.

What is the output of the following program?

a)

15

b)

10

c)

0

d)

12345

15.

What will be the output when the following code runs?

a)

User logged in?: True

b)

User logged in?: False

c)

True

d)

False

16.

The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤. As well, AND, OR and NOT are used instead of and, or and not.

A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.

Determine what the following expression would evaluate to.

a)

yes

b)

true

c)

false

d)

no

17.

The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤. As well, AND, OR and NOT are used instead of and, or and not.

A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.

Which of the following Boolean expressions is equivalent to the expression?

a)

(a AND b) OR c

b)

(a AND b) AND (a AND c)

c)

(b AND c) OR a

d)

a AND (b OR c)

18.

The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤. As well, AND, OR and NOT are used instead of and, or and not.

In the following code block, assume that the variables rainy and tooCold are boolean.

Which of the following are equivalent to the above code block?

a)
b)
c)
d)
19.

Which of the following returns a random number between 1 and 99?

a)

randint(1, 100)

b)

randint(1, 99)

c)

random.randint(1,99)

d)

random.randint(1,100)

20.

Which of the following could NOT be an output from the following code?

a)

50

b)

30

c)

0

d)

90

21.

The AP Exam does not use for loops and while loops, but rather REPEAT or REPEAT UNTIL commands as shown below.

Consider the following program, which is intended to print the sum of all the positive integers up to number.

a)

The program correctly displays the sum of all positive integers from 1 to number

b)

The program does not work as intended but rather it displays the number squared.

c)

The program does not work as intended but rather it displays the number factorial.

d)

The program does not work as intended because sum should be initialized to 1.

22.

The AP Exam does not use for loops and while loops, but rather REPEAT or REPEAT UNTIL commands. Consider the following program, which is intended to print the count of odd numbers between 1 and number

Which of the following best describes the behavior of this program?

a)

The program does not work as intended because it displays the count of even numbers between 1 and number

b)

The program does not work as intended because it displays count but should instead display i

c)

The program does not work as intended because the condition in the if statement needs to say (number MOD 2 = 1)

d)

The program correctly displays the count of odd numbers between 1 and number

23.

The AP Exam does not use for loops and while loops, but rather REPEAT or REPEAT UNTIL commands as shown below. In the procedure Mystery written below, the parameter number is a positive integer. Which of the following best describes the result of running the Mystery procedure?

a)

The result will always be true for any initial value of number

b)

The result will be false whenever the initial value of number is even

c)

The result will always be false for any initial value of number

d)

The result will be false whenever the initial value of number is odd

24.

The AP Exam does not use for loops and while loops, but rather REPEAT or REPEAT UNTIL commands as shown below.

The program below uses a robot in a 5x5 grid of squares. The robot is represented as a triangle, which is initially in the bottom-left square of the grid and facing toward the right of the grid.

After running which of the following code segments would the robot end up in the same place facing the same direction as after running the code segment below?

a)

b)

c)
d)

25.

The AP Exam uses the following relational (comparison) operators: =, ≠, >, <, ≥, and ≤. As well, AND, OR and NOT are used instead of and, or and not.

A county 911 system uses an automated computer program to dispatch one of two ambulances. In order to dispatch the ambulance, the ambulance needs to be available and the emergency needs to be in the ambulance’s primary zone or the other ambulance is not available.

The following boolean variables are used: ambOneAvail - set to true is ambulance one is available, otherwise set to false ambTwoAvail - set to true is ambulance two is available, otherwise set to false inZone - Set to true if the emergency is in the primary zone for the ambulance, otherwise set to false

Which of the following Boolean expressions can be used in a selection statement to cause ambulance one to be dispatched?

a)

b)

c)

d)