WorksheetsUnit 4 Assessment Review
Total questions: 25
Worksheet time: 13mins
What is the last thing printed by the following program?
10
20
30
60
We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?
For Loop
While Loop
Loop and a half
Infinite Loop
How many times will the following program print "hello"?
10
11
9
This code will loop infinitely
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?
Change the True in line 3 to be password != SECRET_PASSWORD so that the program doesn’t loop infinitely
Change the True in line 3 to be password == SECRET_PASSWORD so that the program doesn’t loop infinitely
Add a break; statement after line 6 so that the program doesn’t loop infinitely
Put line 7 inside of an else statement
What will the following program print when run?
4
5
4
5
6
5
4
6
5
4
0
2
6
4
6
5
6
5
What is the value of the boolean variable can_vote at the end of this program?
True
False
Yes
none, there is a syntax error in this code
What will be the output of this program?
0
5
True
Nothing will print
What will be the output of this program?
0
5
True
Nothing will print
What is printed by the following program?
Is it warm: True
Is it warm: False
Is it warm: yes
Is it warm: no
What is printed by the following program?
Hello, we are open! Sincerely, the grocery store
Sorry, we are closed!
Sincerely, the grocery store
Hello, we are open!
Sorry, we are closed!
Sincerely, the grocery store
What will the following program print when run?
Issue Driver’s License
Almost eligible for Driver’s License
No requirements met.
Nothing will print
What will the following program print when run?
1
1
3
5
1
4
1
4
5
We want to print the phrase “CodeHS is the best” exactly 25 times. What kind of control structure should we use?
If Statement
While Loop
Break Statement
For Loop
What is the output of the following program?
15
10
0
12345
What will be the output when the following code runs?
User logged in?: True
User logged in?: False
True
False
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.
yes
true
false
no
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 AND b) OR c
(a AND b) AND (a AND c)
(b AND c) OR a
a AND (b OR c)
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?
Which of the following returns a random number between 1 and 99?
randint(1, 100)
randint(1, 99)
random.randint(1,99)
random.randint(1,100)
Which of the following could NOT be an output from the following code?
50
30
0
90
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.
The program correctly displays the sum of all positive integers from 1 to number
The program does not work as intended but rather it displays the number squared.
The program does not work as intended but rather it displays the number factorial.
The program does not work as intended because sum should be initialized to 1.
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?
The program does not work as intended because it displays the count of even numbers between 1 and number
The program does not work as intended because it displays count but should instead display i
The program does not work as intended because the condition in the if statement needs to say (number MOD 2 = 1)
The program correctly displays the count of odd numbers between 1 and number
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?
The result will always be true for any initial value of number
The result will be false whenever the initial value of number is even
The result will always be false for any initial value of number
The result will be false whenever the initial value of number is odd
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?
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?
