WorksheetsPseudocode APCSP Random
Total questions: 24
Worksheet time: 6hrs 0mins
After running the following code segment, what is contained in the array data?
Choose the best description of what the mystery procedure below does. The procedure accepts two parameters: a list of a values and a number n.
PROCEDURE mystery (list, n)
{
i = 1
REPEAT LENGTH(list) TIMES
{
IF ( list[i] = n )
{
DISPLAY (i)
}
i = i+1
}
}
Mystery displays the number at index n.
Mystery displays the index of the first occurrence of the value n in the list.
Mystery displays the index of the last occurrence of the value n in the list.
Mystery displays the index of every occurrence of the value n in the list.
Mystery displays true if n is in the list.
Which of the following best describes the value returned by the procedure below?
PROCEDURE mystery (data)
{
count = 0
i = 1
REPEAT UNTIL (i = LENGTH(data))
{
IF (data[i] < data[i+1])
{
count = count + 1
}
i = i+1
}
DISPLAY(count)
}
The answers below refer to values being in ascending and descending order. Ascending order means increasing, as in: [1, 2, 5, 8]. Descending order means decreasing, as in [20, 15, 7, 3].
The procedure displays true when data is in ascending order
The procedure displays false when data is in descending order
The procedure displays the number of times adjacent items are in ascending order
The procedure displays how long it takes to find two numbers in ascending order
The procedure counts how long it takes to find two numbers in descending order and displays that number
A robot starts in a grid facing north (B3). What is the robot's location and direction after the following program is executed?
data = ["F", "F", "R", "F", "L", "F", "R", "R", "F"]
FOR EACH move IN data
{
IF ( move = "F" AND CAN_MOVE(forward) )
{
MOVE_FORWARD()
}
ELSE IF (move = "R"){
rotate_right()
}
ELSE IF ( move = "L") {
rotate_left()
}
}
Which of the following best describes the result of running the procedure below?
PROCEDURE mystery (a, b, c)
{
IF ( a >= b AND a >= c)
{
DISPLAY(a)
}
ELSE IF ( b >= a AND b >= c)
{
DISPLAY(b)
}
ELSE
{
DISPLAY(c)
}
}
mystery displays the smallest of the three input values
It displays the middle of the three input values
It displays the largest of the three input values
It displays the average of the three input values
It always displays c
The following program processes the list data shown below. What is the output of the following program?
val = 0
i = 1
REPEAT 3 TIMES
{
val = val + data[i]
i = i + 1
}
DISPLAY (val)
3
9
17
42
The following program processes the list data shown below. After running the following program, what is contained in the list?
i = 1
val = 0
n = LENGTH(data)
REPEAT n TIMES
{
val = val + data[i]
data[i] = val
i = i + 1
}
Assuming that the list data below is given as the parameter to the procedure, what is returned by the following procedure?
val = 0
FOR EACH item IN data
{
IF (item > val)
{
val = item
}
}
DISPLAY(val)
3
4
9
10
16
What are the values of x and y after this script runs?
x is equal to 15; y is equal to 15
x is equal to 5; y is equal to 10
x is equal to 15; y is equal to 10
x is equal to "x + 5"; y is equal to "x"
x is equal to 10, 15; y is equal to 5, 10
What will be displayed after running this code?
All done.
Inside the if.
Inside the if.
All done.
Inside the else.
All done.
Inside the if.
Inside the else.
All done.
How many times will the word "here" be displayed when this code is run?
3
6
10
18
It will be difference each time you run it.
a, b, and tmp are variables. What does this script do?
makes a and b equal to each other
this code doesn't do anything
rearranges the variables a, b, and tmp.
swaps the values of a and b
This program causes an error
What will be displayed after running this code?
y + z + " and " + x
sentence
BoysHello Girls
Hello Boys and Girls
Hello Girls and Boys
What will be displayed after running this code?
Under 40
And under 21
And contains a 3
Under 40
And under 21
And contains a 3
Nothing will be displayed
What will be displayed after running this code?
The word is too short!
The word it too long!
The word is just right!
The word is still too short!
The word is just right!
The word is still too short!
What will be printed when this code is run?
REPEAT 3 TIMES
{
DISPLAY ("apple")
DISPLAY ("orange")
}
apple
apple
apple
orange
orange
orange
apple
orange
apple
orange
apple
orange
apple
orange
Nothing with be printed
It will be different each time you run it
How many times will the word "here" be displayed when this code is run?
0
1
5
10
"here" will displayed over and over until the code is stopped manually
What will be displayed when this code is run?
func1
func2
in func1
in func2
in func1
in func2
in func1
in func2
in func1
DISPLAY in func1
DISPLAY in func2
Nothing is printed
What will be displayed when this code is run?
func3
func1
in func3
in func3
in func1
in func3
in func1
in func3
in func3 will be displayed over and over until the code is stopped manually
in func3
in func1
func3
func1
What are x, y and z equal to after this script is run?
x is equal to 8; y is equal to 8; z is equal to 12
x is equal to 8; y is equal to 4; z is equal to 84
x is equal to 8; y is equal to 8; z is equal to 16
x is equal to 8; y is equal to 8; z is equal to "x + y"
x is equal to 8; y is equal to 4, 8; z is equal to 12
For the following problem, assume list is a variable that contains a list of random integers. What does this program do?
displays true if the number 100 is in the list
displays true if the first number in the list is 100
displays true if the last number in the list is 100
displays true if there are 100 numbers in the list
displays true or false 100 times
What are x, y, and z equal to after this program is run?
x is equal to "yes"; y is equal to "maybe"; z is equal to "no"
x is equal to "no"; y is equal to "maybe"; z is equal to "yes"
x is equal to "no"; y is equal to "maybe"; z is equal to "x"
x is equal to "yes, no"; y is equal to "yes, maybe"; z is equal to "yes, no"
x is equal to "no"; y is equal to "maybe"; z is equal to "no"
What will be displayed when this code is run?
5
4
3
2
1
0
5
3
1
3
1
-1
3
1
3
What does this code do?
Makes sure the value of x is not equal to 10
Makes sure the value of x is less than 5
Makes sure the value of x is between 10 and 5
It always sets x equal to 5
This code will cause an error
