wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Pseudocode APCSP Random

Total questions: 24

Worksheet time: 6hrs 0mins

Name
Class
Date
1.

After running the following code segment, what is contained in the array data?

a)
b)
c)
d)
e)
2.

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

}

}

a)

Mystery displays the number at index n.

b)

Mystery displays the index of the first occurrence of the value n in the list.

c)

Mystery displays the index of the last occurrence of the value n in the list.

d)

Mystery displays the index of every occurrence of the value n in the list.

e)

Mystery displays true if n is in the list.

3.

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].

a)

The procedure displays true when data is in ascending order

b)

The procedure displays false when data is in descending order

c)

The procedure displays the number of times adjacent items are in ascending order

d)

The procedure displays how long it takes to find two numbers in ascending order

e)

The procedure counts how long it takes to find two numbers in descending order and displays that number

4.

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()

}

}

a)
b)
c)
d)
e)
5.

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)

}

}

a)

mystery displays the smallest of the three input values

b)

It displays the middle of the three input values

c)

It displays the largest of the three input values

d)

It displays the average of the three input values

e)

It always displays c

6.

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)

a)

3

b)

9

c)

17

d)

42

7.

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

}

a)
b)
c)
d)
8.

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)

a)

3

b)

4

c)

9

d)

10

e)

16

9.

What are the values of x and y after this script runs?

a)

x is equal to 15; y is equal to 15

b)

x is equal to 5; y is equal to 10

c)

x is equal to 15; y is equal to 10

d)

x is equal to "x + 5"; y is equal to "x"

e)

x is equal to 10, 15; y is equal to 5, 10

10.

What will be displayed after running this code?

a)

All done.

b)

Inside the if.

c)

Inside the if.

All done.

d)

Inside the else.

All done.

e)

Inside the if.

Inside the else.

All done.

11.

How many times will the word "here" be displayed when this code is run?

a)

3

b)

6

c)

10

d)

18

e)

It will be difference each time you run it.

12.

a, b, and tmp are variables. What does this script do?

a)

makes a and b equal to each other

b)

this code doesn't do anything

c)

rearranges the variables a, b, and tmp.

d)

swaps the values of a and b

e)

This program causes an error

13.

What will be displayed after running this code?

a)

y + z + " and " + x

b)

sentence

c)

BoysHello Girls

d)

Hello Boys and Girls

e)

Hello Girls and Boys

14.

What will be displayed after running this code?

a)

Under 40

b)

And under 21

c)

And contains a 3

d)

Under 40

And under 21

And contains a 3

e)

Nothing will be displayed

15.

What will be displayed after running this code?

a)

The word is too short!

b)

The word it too long!

c)

The word is just right!

d)

The word is still too short!

e)

The word is just right!

The word is still too short!

16.

What will be printed when this code is run?


REPEAT 3 TIMES

{

DISPLAY ("apple")

DISPLAY ("orange")

}

a)

apple

apple

apple

orange

orange

orange

b)

apple

orange

c)

apple

orange

apple

orange

apple

orange

d)

Nothing with be printed

e)

It will be different each time you run it

17.

How many times will the word "here" be displayed when this code is run?

a)

0

b)

1

c)

5

d)

10

e)

"here" will displayed over and over until the code is stopped manually

18.

What will be displayed when this code is run?


func1

func2

a)

in func1

in func2

b)

in func1

in func2

c)

in func1

in func2

in func1

d)

DISPLAY in func1

DISPLAY in func2

e)

Nothing is printed

19.

What will be displayed when this code is run?


func3

func1

a)

in func3

in func3

in func1

b)

in func3

in func1

in func3

c)

in func3 will be displayed over and over until the code is stopped manually

d)

in func3

in func1

e)

func3

func1

20.

What are x, y and z equal to after this script is run?

a)

x is equal to 8; y is equal to 8; z is equal to 12

b)

x is equal to 8; y is equal to 4; z is equal to 84

c)

x is equal to 8; y is equal to 8; z is equal to 16

d)

x is equal to 8; y is equal to 8; z is equal to "x + y"

e)

x is equal to 8; y is equal to 4, 8; z is equal to 12

21.

For the following problem, assume list is a variable that contains a list of random integers. What does this program do?

a)

displays true if the number 100 is in the list

b)

displays true if the first number in the list is 100

c)

displays true if the last number in the list is 100

d)

displays true if there are 100 numbers in the list

e)

displays true or false 100 times

22.

What are x, y, and z equal to after this program is run?

a)

x is equal to "yes"; y is equal to "maybe"; z is equal to "no"

b)

x is equal to "no"; y is equal to "maybe"; z is equal to "yes"

c)

x is equal to "no"; y is equal to "maybe"; z is equal to "x"

d)

x is equal to "yes, no"; y is equal to "yes, maybe"; z is equal to "yes, no"

e)

x is equal to "no"; y is equal to "maybe"; z is equal to "no"

23.

What will be displayed when this code is run?

a)

5

4

3

2

1

0

b)

5

3

1

c)

3

1

-1

d)

3

1

e)

3

24.

What does this code do?

a)

Makes sure the value of x is not equal to 10

b)

Makes sure the value of x is less than 5

c)

Makes sure the value of x is between 10 and 5

d)

It always sets x equal to 5

e)

This code will cause an error