Ap Comp Sci 3.8 Iteration Quiz

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/30

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:07 AM on 1/27/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

31 Terms

1
New cards
<p><br></p><p><strong>A </strong><span><span>j = -5</span></span>, <span><span>k = 5</span></span></p><p><strong>B </strong><span><span>j = 0</span></span>, <span><span>k = 5</span></span></p><p><strong>C </strong><span><span>j = 5</span></span>, <span><span>k = 0</span></span></p><p><strong>D </strong><span><span>j = 5</span></span>, <span><span>k = -5</span></span></p>


A j = -5, k = 5

B j = 0, k = 5

C j = 5, k = 0

D j = 5, k = -5

D

2
New cards
<p><br></p><p><strong>A) </strong><span><span>7</span></span></p><p><strong>B) </strong><span><span>9</span></span></p><p><strong>C) </strong><span><span>10</span></span></p><p><strong>D) </strong><span><span>12</span></span></p>


A) 7

B) 9

C) 10

D) 12

D

3
New cards
<p><br>Which of the following code segments can be used to draw the figure?</p><p>Responses</p><p><strong>A</strong></p><p class="code_line">xVal 1</p><p class="code_line">yVal 0</p><p class="code_line">len 1</p><p class="code_line">REPEAT 5 TIMES</p><p class="code_line">{</p><p class="code_line indent:3">drawLine(xVal, yVal, xVal, yVal + len)</p><p class="code_line indent:3">xVal xVal + 1</p><p class="code_line indent:3">len len + 1</p><p class="code_line">}</p><p><strong>B</strong></p><p class="code_line">xVal 1</p><p class="code_line">yVal 0</p><p class="code_line">len 1</p><p class="code_line">REPEAT 5 TIMES</p><p class="code_line">{</p><p class="code_line indent:3">drawLine(xVal, yVal, xVal + len, yVal)</p><p class="code_line indent:3">yVal yVal + 1</p><p class="code_line indent:3">len len + 1</p><p class="code_line">}</p><p><strong>C</strong></p><p class="code_line">xVal 5</p><p class="code_line">yVal 0</p><p class="code_line">len 5</p><p class="code_line">REPEAT 5 TIMES</p><p class="code_line">{</p><p class="code_line indent:3">drawLine(xVal, yVal, xVal, yVal + len)</p><p class="code_line indent:3">xVal xVal - 1</p><p class="code_line">}</p><p><strong>D</strong></p><p class="code_line">xVal 5</p><p class="code_line">yVal 0</p><p class="code_line">len 5</p><p class="code_line">REPEAT 5 TIMES</p><p class="code_line">{</p><p class="code_line indent:3">drawLine(xVal, yVal, xVal + len, yVal)</p><p class="code_line indent:3">yVal yVal - 1</p><p class="code_line indent:3">len len - 1</p><p class="code_line">}</p>


Which of the following code segments can be used to draw the figure?

Responses

A

xVal 1

yVal 0

len 1

REPEAT 5 TIMES

{

drawLine(xVal, yVal, xVal, yVal + len)

xVal xVal + 1

len len + 1

}

B

xVal 1

yVal 0

len 1

REPEAT 5 TIMES

{

drawLine(xVal, yVal, xVal + len, yVal)

yVal yVal + 1

len len + 1

}

C

xVal 5

yVal 0

len 5

REPEAT 5 TIMES

{

drawLine(xVal, yVal, xVal, yVal + len)

xVal xVal - 1

}

D

xVal 5

yVal 0

len 5

REPEAT 5 TIMES

{

drawLine(xVal, yVal, xVal + len, yVal)

yVal yVal - 1

len len - 1

}

A

4
New cards
<p>What is displayed as a result of executing the algorithm in the flowchart?</p><p>Responses</p><p><strong>A</strong></p><p>5</p><p><strong>B</strong></p><p>15</p><p><strong>C</strong></p><p>1 2 3 4</p><p><strong>D</strong></p><p>1 2 3 4 5</p>

What is displayed as a result of executing the algorithm in the flowchart?

Responses

A

5

B

15

C

1 2 3 4

D

1 2 3 4 5

a

5
New cards
<p><br></p><p><strong>A</strong></p><p class="choice_paragraph"></p><img src="https://assets.learnosity.com/organisations/537/VR113799.g16.png" data-width="100%" data-align="center" alt="The figure presents two blocks of code that consist of 8 lines. The second block of code contains nested blocks of code. Line 1: [begin block] n ← 1 [end block] Line 2: [Begin block] REPEAT 3 TIMES [Begin block] Line 3: [begin block] n ← n + 1 [end block] Line 4: [Begin block] REPEAT n TIMES [Begin block] Line 5: [begin block] MOVE_FORWARD [end block] Line 6: [begin block] ROTATE_LEFT [end block] Line 7: [begin block] MOVE_FORWARD [end block] Line 8: [begin block] ROTATE_RIGHT [end block] [End block] [End block] [End block] [End block]"><p><strong>B</strong></p><p class="choice_paragraph"></p><img src="https://assets.learnosity.com/organisations/537/VR113799.g14.png" data-width="100%" data-align="center" alt="The figure presents two blocks of code that consist of 8 lines. The second block of code contains nested blocks of code. Line 1: [begin block] n ← 1 [end block] Line 2: [Begin block] REPEAT 3 TIMES [Begin block] Line 3: [Begin block] REPEAT n TIMES [Begin block] Line 4: [begin block] MOVE_FORWARD [end block] Line 5: [begin block] ROTATE_LEFT [end block] Line 6: [begin block] MOVE_FORWARD [end block] Line 7: [begin block] ROTATE_RIGHT [end block] [End block] [End block] Line 8: [begin block] n ← n + 1 [end block] [End block] [End block]"><p><strong>C</strong></p><p class="choice_paragraph"></p><p><strong>D</strong></p><p class="choice_paragraph"></p><img src="https://assets.learnosity.com/organisations/537/VR113799.g18.png" data-width="100%" data-align="center" alt="The figure presents two blocks of code that consist of 9 lines. The second block of code contains nested blocks of code. Line 1: [begin block] n ← 1 [end block] Line 2: [Begin block] REPEAT 3 TIMES [Begin block] Line 3: [Begin block] REPEAT n TIMES [Begin block] Line 4: [begin block] MOVE_FORWARD [end block] [End block] [End block] Line 5: [begin block] ROTATE_LEFT [end block] Line 6: [Begin block] REPEAT n TIMES [Begin block] Line 7: [begin block] MOVE_FORWARD [end block] [End block] [End block] Line 8: [begin block] ROTATE_RIGHT [end block] Line 9: [begin block] n ← n + 1 [end block] [End block] [End block]"><p></p>


A

The figure presents two blocks of code that consist of 8 lines. The second block of code contains nested blocks of code. Line 1: [begin block] n ← 1 [end block] Line 2: [Begin block] REPEAT 3 TIMES [Begin block] Line 3: [begin block] n ← n + 1 [end block] Line 4: [Begin block] REPEAT n TIMES [Begin block] Line 5: [begin block] MOVE_FORWARD [end block] Line 6: [begin block] ROTATE_LEFT [end block] Line 7: [begin block] MOVE_FORWARD [end block] Line 8: [begin block] ROTATE_RIGHT [end block] [End block] [End block] [End block] [End block]

B

The figure presents two blocks of code that consist of 8 lines. The second block of code contains nested blocks of code. Line 1: [begin block] n ← 1 [end block] Line 2: [Begin block] REPEAT 3 TIMES [Begin block] Line 3: [Begin block] REPEAT n TIMES [Begin block] Line 4: [begin block] MOVE_FORWARD [end block] Line 5: [begin block] ROTATE_LEFT [end block] Line 6: [begin block] MOVE_FORWARD [end block] Line 7: [begin block] ROTATE_RIGHT [end block] [End block] [End block] Line 8: [begin block] n ← n + 1 [end block] [End block] [End block]

C

D

The figure presents two blocks of code that consist of 9 lines. The second block of code contains nested blocks of code. Line 1: [begin block] n ← 1 [end block] Line 2: [Begin block] REPEAT 3 TIMES [Begin block] Line 3: [Begin block] REPEAT n TIMES [Begin block] Line 4: [begin block] MOVE_FORWARD [end block] [End block] [End block] Line 5: [begin block] ROTATE_LEFT [end block] Line 6: [Begin block] REPEAT n TIMES [Begin block] Line 7: [begin block] MOVE_FORWARD [end block] [End block] [End block] Line 8: [begin block] ROTATE_RIGHT [end block] Line 9: [begin block] n ← n + 1 [end block] [End block] [End block]

d

6
New cards

Which of the following algorithms display all integers between 1 and 20, inclusive, that are not divisible by 3 ?

Select two answers.


A

Step 1:

Set x to 0.

 Step 2:

Increment x by 1.

 Step 3:

If x is not divisible by 3, then display x.

 Step 4:

Repeat steps 2 and 3 until x is 20.

B

Step 1:

Set x to 0.

Step 2: If x is divisible by 3, then display x.Step 3:

Increment x by 1.

 Step 4: Repeat steps 2 and 3 until x is greater than 20.

C

Step 1:

Set x to 1.

    Step 2: If x is divisible by 3, then do nothing; otherwise display x.Step 3:

Increment x by 1.

  Step 4: Repeat steps 2 and 3 until x is 20.

D

Step 1:

Set x to 1.

  Step 2: If x is divisible by 3, then do nothing; otherwise display x.Step 3:

Increment x by 1.

  Step 4: Repeat steps 2 and 3 until x is greater than 20.

A, D

7
New cards

The following algorithm is intended to determine the average height, in centimeters, of a group of people in a room. Each person has a card, a pencil, and an eraser. Step 2 of the algorithm is missing.

Step 1: All people stand up.

Step 2: (missing step)

Step 3: Each standing person finds another standing person and they form a pair. If a person cannot find an unpaired standing person, that person remains standing and waits until the next opportunity to form pairs.

Step 4: In each pair, one person hands their card to the other person and sits down.

Step 5: At this point, the standing person in each pair is holding two cards. The standing person in each pair replaces the top number on their card with the sum of the top numbers on the two cards and replaces the bottom number on their card with the sum of the bottom numbers on the two cards. The sitting partner’s card is discarded.

Step 6: Repeat steps 3–5 until there is only one person standing.

Step 7: The last person standing divides the top number by the bottom number to determine the average height.

Which of the following can be used as step 2 so that the algorithm works as intended?

Responses

A

Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 1 at the bottom of the card.

B

Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 2 at the bottom of the card.

C

Step 2: Each person writes the number 1 at the top of the card and writes their height, in centimeters, at the bottom of the card.

D

Step 2: Each person writes the number 2 at the top of the card and writes their height, in centimeters, at the bottom of the card.


a

8
New cards

Suppose a large group of people in a room were all born in the same year. Consider the following three algorithms, which are each intended to identify the people in the room who have the earliest birthday based on just the month and day. For example, a person born on February 10 is considered to have an earlier birthday than a person born on March 5. Which of the three algorithms will identify the correct people?

  1. All the people in the room stand up. All standing people form pairs where possible, leaving at most one person not part of a pair. For each pair, the person with the earlier birthday remains standing, while the other person in the pair sits down. If there is a tie, both people sit down. Any individual not part of a pair remains standing. Continue doing this until only one person remains standing. That person has the earliest birthday.

  2. All the people in the room stand up. All standing people form pairs with another standing person that they have not previously been paired with where possible, leaving at most one person not part of a pair. For each pair, the person with the earlier birthday remains standing, while the other person in the pair sits down. If there is a tie, both people in the pair remain standing. Any individual not part of a pair remains standing. Continue doing this until only one person remains standing or all persons standing have the same birthday. Anyone still standing has the earliest birthday.

  3. Beginning with the number 1, ask if anyone was born on that day of any month. Continue with the numbers 2, 3, and so on until a positive response is received. If only one person responds, that person has the earliest birthday. If more than one person responds, determine which person was born in the earliest month, and that person or those persons have the earliest birthday.

Responses

A

I only

B

II only

C

I and II

D

II and III

B

9
New cards

Consider the following code segment.

The figure presents seven blocks of code that consist of 9 total lines. Throughout the fourth block of code are nested blocks of code. Line 1: [begin block] a ← true [end block] Line 2: [begin block] b ← false [end block] Line 3: [begin block] c ← true [end block] [Begin Block] Line 4: REPEAT UNTIL [begin block] a and b [end block] [Begin Block] Line 5: [begin block] c ← NOT c [end block] Line 6: [begin block] b ← c [end block] [End Block] [End Block] Line 7: [begin block] DISPLAY [begin block] a [end block] [end block] Line 8: [begin block] DISPLAY [begin block] b [end block] [end block] Line 9: [begin block] DISPLAY [begin block] c [end block] [end block]

What is displayed as a result of executing the code segment?

Responses

A

true false false

B

true false true

C

true true false

D

true true true


d

10
New cards

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the center square and facing toward the top of the grid.

The figure presents a robot in a 5 by 5 grid of squares. The robot is represented by a triangle which is initially in the in the center (the third square from the left and third square from the bottom), and it is initially facing the top of the grid.

The following code segment is used to move the robot in the grid.

count 1

REPEAT 4 TIMES

{

REPEAT count TIMES

{

MOVE_FORWARD()

}

ROTATE_LEFT()

count count + 1

}

Which of the following code segments will move the robot from the center square along the same path as the code segment above?

Responses

A

count 0

REPEAT 4 TIMES

{

count count + 1

REPEAT count TIMES

{

MOVE_FORWARD()

}

ROTATE_LEFT()

}

B

count 0

REPEAT 4 TIMES

{

count count + 1

ROTATE_LEFT()

REPEAT count TIMES

{

MOVE_FORWARD()

}

}

C

count 0

REPEAT 4 TIMES

{

REPEAT count TIMES

{

ROTATE_LEFT()

}

MOVE_FORWARD()

count count + 1

}

D

count 0

REPEAT 4 TIMES

{

ROTATE_LEFT()

REPEAT count TIMES

{

MOVE_FORWARD()

}

count count + 1

}

a

11
New cards

The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially facing right.

The figure presents a robot in a grid of squares with 7 columns and 6 rows. The robot is represented by a triangle, which is initially in the bottom left square of the grid, facing rightwards. A path of arrows shows the robot’s movement from its initial location to a gray square in the top right square of the grid. The path the robot takes is as follows. The robot moves 2 squares to the right, turns upwards, moves 2 squares upwards, turns rightwards, moves 4 squares to the right, turns upwards, moves 3 squares upwards where it turns rightwards and ends.

Consider the following procedure.

The figure presents a block of code that consists of 7 lines. Throughout the code there are nested blocks of code, as follows. [Begin Block] Line 1: PROCEDURE botStepper [begin block] n [end block] [Begin Block] Line 2: [Begin Block] REPEAT n TIMES [Begin Block] Line 3: [begin block] MOVE_FORWARD [end block] [End Block] [End Block] Line 4: [begin block] ROTATE_LEFT [end block] [Begin Block] Line 5: REPEAT n TIMES [Begin Block] Line 6: [begin block] MOVE_FORWARD [end block] [End block] [End Block] Line 7: [begin block] ROTATE_RIGHT [end block] [End Block] [End Block]

Which of the following code segments will move the robot to the gray square along the path indicated by the arrows?

Responses

A

The figure presents two lines of code. Throughout the code there are nested blocks of code, as follows. Line 1: [begin block] botStepper [begin block] 2 [end block] [end block] Line 2: [begin block] botStepper [begin block] 3 [end block] [end block]

B

The figure presents two lines of code. Throughout the code there are nested blocks of code, as follows. Line 1: [begin block] botStepper [begin block] 3 [end block] [end block] Line 2: [begin block] botStepper [begin block] 4 [end block] [end block]

C

The figure presents three lines of code. Throughout the code there are nested blocks of code, as follows. Line 1: [begin block] botStepper [begin block] 2 [end block] [end block] Line 2: [begin block] MOVE_FORWARD [end block] Line 3: [begin block] botStepper [begin block] 3 [end block] [end block]

D

The figure presents three lines of code. Throughout the code there are nested blocks of code, as follows. Line 1: [begin block] botStepper [begin block] 3 [end block] [end block] Line 2: [begin block] MOVE_FORWARD [end block] Line 3: [begin block] botStepper [begin block] 4 [end block] [end block]

c

12
New cards

An algorithm is intended to display the following output.

red red blue red red blue red red blue

Which of the following code segments can be used to display the intended output?

Responses

A

The figure presents one block of code that consists of 4 total lines. Throughout the block of code there are nested blocks of code. [Begin Block] Line 1: REPEAT 2 TIMES [Begin Block] [Begin Block] Line 2: REPEAT 3 TIMES [Begin Block] Line 3: [begin block] DISPLAY [begin block] “red” [end block] [end block]  [End Block] [End Block] Line 4: [begin block] DISPLAY [begin block] “blue” [end block] [end block] [End Block] [End Block]

B

The figure presents one block of code that consists of 4 total lines. Throughout the block of code there are nested blocks of code. [Begin Block] Line 1: REPEAT 2 TIMES [Begin Block] [Begin Block] Line 2: REPEAT 3 TIMES [Begin Block] Line 3: [begin block] DISPLAY [begin block] “blue” [end block] [End block]  [End Block] [End Block] Line 4: [begin block] DISPLAY [begin block] “red” [end block] [end block] [End Block] [End Block]

C

The figure presents one block of code that consists of 4 total lines. Throughout the block of code there are nested blocks of code. [Begin Block] Line 1: REPEAT 3 TIMES [Begin Block] [Begin Block] Line 2: REPEAT 2 TIMES [Begin Block] Line 3: [begin block] DISPLAY [begin block] “red” [end block] [end block] [End Block] [End Block] Line 4: [begin block] DISPLAY [begin block] “blue” [end block] [end block] [End Block] [End Block]

D

The figure presents two blocks of code that consist of 4 total lines. Throughout the first block of code there are nested blocks of code. [Begin Block] Line 1: REPEAT 3 TIMES [Begin Block] [Begin Block] Line 2: REPEAT 2 TIMES [Begin Block] Line 3: [begin block] DISPLAY [begin block] “blue” [end block] [end block] [End Block] [End Block] Line 4: [begin block] DISPLAY [begin block] “red” [end block] [end block] [End Block] [End Block]

c

13
New cards

Consider the following program code.

 

The block code consists of seven lines with some of the lines indented. Line one: begin block, lowercase i left arrow zero end  block. Line two: begin block, sum left arrow zero end block. Begin block Line three: all capital REPEAT UNTIL, begin block, lowercase  i equals four, end block. Begin block. Line four is indented one tab: begin block, i left arrow one end block. Line five is indented one tab: begin block, sum left arrow sum plus lowercase i, end block. Line six is indented one tab: begin block, lowercase i left  arrow lowercase i plus one end block. End block, end block. Line seven: begin block, all capitals DISPLAY, begin block, sum, end block. End block.

Which of the following best describes the result of running the program code?

Responses

A

The number 0 is displayed.

B

The number 6 is displayed.

C

The number 10 is displayed.

D

Nothing is displayed; the program results in an infinite loop.

d

14
New cards

The question below uses a robot in a 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 top of the grid.

 

A five by five square grid is shown with a triangle pointing up in the square in the lower left corner, in the first column and fifth row.

Code for the procedure Mystery is shown below. Assume that the parameter p has been assigned a positive integer value (e.g., 1, 2, 3, …).

A segment of code is shown in a grey box. In the upper left of the box it reads PROCEDURE Mystery, the p, which is written in a square. Below this and indented is a smaller grey box that has a white border. In the upper left of this smaller grey box it reads REPEAT p times. Below this an indented is a white box, in which there are three smaller white boxes in a column. The top box reads MOVE_FORWARD, the middle box reads MOVE_FORWARD, and the bottom box reads ROTATE_RIGHT.

Which of the following shows a possible result of calling the procedure?

Responses

A

Choice A is a five by five square grid with a triangle in one of the squares. In choice A, the triangle is pointing to the left and is in the third column and fifth row.

B

Choice B is a five by five square grid with a triangle in one of the squares. In choice B, the triangle pointing down and is in the fourth column and second row.

C

Choice C is a five by five square grid with a triangle in one of the squares. In choice C, the triangle is pointing down and in the first column and fifth row.

D

Choice D is a five by five square grid with a triangle in one of the squares. In choice D, the triangle is pointing up and is in the center square, in the third column and third row.

A

15
New cards

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case.

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

 

The figure shows a 5 by 5 grid. There is an upward-facing triangle representing a robot in the bottom-right square. The top-left square of the grid is gray.

Which of the following code segments can be used to move the robot to the gray square?

Select two answers.

response - correct

Responses

A

A coding program reads as follows. Line 1: Repeat 4 times. Line 2: Left curly bracket. Line 3: Move underscore forward left parenthesis right parenthesis. Line 4: Rotate underscore left  parenthesis right parenthesis. Line 5: Move underscore forward left parenthesis right parenthesis. Line 6: Rotate underscore right left parenthesis right parenthesis. Line 7: Right curly bracket.

B

A coding program reads as follows. Line 1: Repeat 4 times. Line 2: Left curly bracket. Line 3: Rotate underscore right left parenthesis right parenthesis. Line 4: Move underscore forward left parenthesis right parenthesis. Line 5: Move underscore forward left parenthesis right parenthesis. Line 6: Rotate underscore right left parenthesis right parenthesis. Line 7: Right curly bracket.

C

A coding program reads as follows. Line 1: Repeat 2 times. Line 2: Left curly bracket. Line 3: Repeat 4 times. Line 4: Left curly bracket. Line 5: Move underscore forward left parenthesis right parenthesis. Line 6: Right curly bracket. Line 7: Rotate underscore right left parenthesis right parenthesis. Line 8: Right curly bracket.

D

A coding program reads as follows. Line 1: Repeat 2 times. Line 2: Left curly bracket. Line 3: Repeat 2 times. Line 4: Move underscore forward left parenthesis right parenthesis. Line 5: Move underscore forward left parenthesis right parenthesis. Line 6: Rotate underscore right left parenthesis right parenthesis. Line 7: Right curly bracket. Line 8: Right curtly bracket.

A, C

16
New cards

Consider the following code segment.

A segment of code is shown. At the top is a white box that reads j left arrow 1. This is at the top left corner of a larger grey box, at the top of which it reads REPEAT UNTIL, the left angle bracket MISSING CONDITION right angle bracket, which is encircled. Below this in the grey box and indented is a white box that reads j left arrow j plus 2.

Which of the following replacements for <MISSING CONDITION> will result in an infinite loop?

Responses

A

j = 6

B

j ≥ 6

C

j = 7

D

j > 7

a

17
New cards

Consider the following procedure.

Procedure Call

Explanation

drawCircle(xPos, yPos, rad)

Draws a circle on a coordinate grid with center (xPos, yPos) and radius rad

The drawCircle procedure is to be used to draw the following figure on a coordinate grid.

The figure presents the graph of three circles, one small, one medium, and one large, in the first quadrant of a coordinate plane with the origin labeled O. The x and y axes each have the numbers 1 through 8 indicated.  The largest circle is centered at the coordinates 4 comma 4 and has a radius of 3 units. The medium size circle is centered at the coordinates 4 comma 3 and has a radius of 2 units. The smallest circle is centered at the coordinates 4 comma 2 and has a radius of 1 unit.

Which of the following code segments can be used to draw the figure?

Select two answers.

response - correct

Responses

A

x 4

y 1

r 0

REPEAT 3 TIMES

{

drawCircle(x, y, r)

r r + 1

y y + 1

}

B

x 4

y 1

r 0

REPEAT 3 TIMES

{

r r + 1

y y + 1

drawCircle(x, y, r)

}

C

x 4

y 4

r 3

REPEAT 3 TIMES

{

drawCircle(x, y, r)

y y - 1

r r - 1

}

D

x 4

y 4

r 3

REPEAT 3 TIMES

{

y y - 1

r r - 1

drawCircle(x, y, r)

}

B, C

18
New cards

Consider the following program.

The block code consists of 6 lines. Line 1: count, left arrow, 1 Line 2: sum, left arrow, zero Begin block Line 3: REPEAT 10 TIMES Begin block Line 4, indented 1 tab: sum, left arrow, sum plus count Line 5, indented 1 tab: count, left arrow, count plus 2 End block End block Line 6: DISPLAY, begin block, sum, end block

Which of the following describes the result of executing the program?

Responses

A

The program displays the sum of the even integers from 0 to 10.

B

The program displays the sum of the even integers from 0 to 20.

C

The program displays the sum of the odd integers from 1 to 9.

D

The program displays the sum of the odd integers from 1 to 19.

D

19
New cards
<p><strong>A</strong></p><img src="https://assets.learnosity.com/organisations/537/f1f8d7d6-4c2b-4d67-80a6-4dbcbb7ec53d.jpg" data-width="100%" data-align="center" alt="End minus start plus 1"><p><strong>B</strong></p><img src="https://assets.learnosity.com/organisations/537/0eb5f228-3321-41d3-a17b-e4713551815e.jpg" data-width="100%" data-align="center" alt="End minus start plus 6"><p><strong>C</strong></p><img src="https://assets.learnosity.com/organisations/537/3dc7af83-b089-4837-b782-6ce26c839cb5.jpg" data-width="100%" data-align="center" alt="Open parenthesis, open parenthesis, end minus start, close parenthesis, divided by 5, close parenthesis, plus 1"><p><strong>D</strong></p><img src="https://assets.learnosity.com/organisations/537/03e8b6b3-45c6-42a8-b347-049df5080016.jpg" data-width="100%" data-align="center" alt="5, times, open parenthesis, end minus start, close parenthesis, plus 1"><p></p>

A

End minus start plus 1

B

End minus start plus 6

C

Open parenthesis, open parenthesis, end minus start, close parenthesis, divided by 5, close parenthesis, plus 1

D

5, times, open parenthesis, end minus start, close parenthesis, plus 1

C

20
New cards

In the following procedure, the parameter n is an integer greater than 2.

The figure presents a block of code that consists of 7 lines. Throughout the code there are nested blocks of code, as follows. [Begin Block] Line 1: PROCEDURE compute [begin block] n [end block] [Begin Block] Line 2: [begin block] result ← 1 [end block] Line 3: [begin block] j ← 2 [end block] [Begin Block] Line 4: REPEAT UNTIL [begin block] j ˃ 2 [end block] [Begin Block] Line 5: [begin block] result ← result + j [end block] Line 6: [begin block] j ← j + 1 [end block] [End Block] [End Block] Line 7: [begin block] RETURN [begin block] result [end block] [end block] [End Block] [End Block]

Which of the following best describes the value returned by the procedure?

Responses

A

The procedure returns nothing because it will not terminate.

B

The procedure returns the value of 2 * n.

C

The procedure returns the value of n * n.

D

The procedure returns the sum of the integers from 1 to n.

D

21
New cards

The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom left square of the grid and facing right.

A 5 by 5 grid with a right-facing triangle at the bottom of the first column.

Consider the following code segment, which moves the robot in the grid.

The block code consists of six lines. Some of the lines of code are indented. Line one: begin block, n, left arrow, three end block.  Begin block Line two: in capital letters, REPEAT 3 TIMES Begin block Begin block Line three indented one tab, reads REPEAT n TIMES.  Line four, indented two tabs, reads MOVE underscore FORWARD. Line five indented one tab, reads ROTATE underscore LEFT. Line six, indented one tab, reads n left arrow n minus one. End block End block

Which of the following shows the location of the robot after running the code segment?

Responses

A

Choice A is a five by five square grid with a triangle pointing down in one of the squares. In choice A, the triangle is in the center square in the third row and third column.

B

 

Choice B is a five by five square grid with a triangle pointing down in one of the squares. In choice B, the triangle is in the square in the second column and third row.

C

 

Choice C is a five by five square grid with a triangle pointing down in one of the squares. In choice C, the triangle is in the square in the first column and third row.

D

 

Choice D is a five by five square grid with a triangle pointing down in one of the squares. In choice D, the triangle is in the square in the first column and second row.

A

22
New cards

The grid below contains a robot represented as a triangle, initially facing right. The robot can move into a white or gray square but cannot move into a black region.

The figure presents a robot in a 5 by 5 grid of squares. The robot is represented by a triangle, which is located in the top leftmost square and is initially facing right. Black squares represent barriers that the robot cannot pass through. The second row contains black shading in the first, second, third, and fourth squares from the left. The third row contains gray shading in the first square, and black shading in the second and fourth squares from the left. The fourth row contains black shading in the second and fourth squares from the left.

The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise.

REPEAT UNTIL (GoalReached ())

{

<MISSING CODE>

}

Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square?

Responses

A

REPEAT UNTIL (CAN_MOVE (forward) = false)

{

ROTATE_RIGHT ()

}

MOVE_FORWARD ()

B

REPEAT UNTIL (CAN_MOVE (forward) = false)

{

MOVE_FORWARD ()

}

ROTATE_RIGHT ()

C

REPEAT UNTIL (CAN_MOVE (right))

{

ROTATE_RIGHT ()

}

MOVE_FORWARD ()

D

REPEAT UNTIL (CAN_MOVE (right))

{

MOVE_FORWARD ()

}

ROTATE_RIGHT ()

B

23
New cards

The following code segment is intended to remove all duplicate elements in the list myList.The procedure does not work as intended.

j LENGTH(myList)

REPEAT UNTIL(j = 1)

{

IF(myList[j] = myList[j - 1])

{

REMOVE(myList, j)

}

j j - 1

}

For which of the following contents of myList will the procedure NOT produce the intended results?

Select two answers.

response - correct

Responses

A

[10, 10, 20, 20, 10, 10]

B

[30, 30, 30, 10, 20, 20]

C

[30, 50, 40, 10, 20, 40]

D

[50, 50, 50, 50, 50, 50]

A, C

24
New cards

Consider the following code segment.

The figure presents three blocks of code that consist of 5 total lines. Throughout the third block of code are nested blocks of code. Line 1: [begin block] x ← 0 [end block] Line 2: [begin block] result ← 0 [end block] [Begin Block] Line 3: REPEAT UNTIL [begin block] x is greater than 5 [end block] [Begin Block] Line 4: [begin block] result ← result plus x [end block] Line 5: [begin block] x ← x plus 1 [end block] [End Block] [End Block]

What is the value of result after the code segment is executed?

Responses

A

6

B

10

C

15

D

21

C

25
New cards
<p><strong>A</strong></p><p class="choice_paragraph">I only</p><p><strong>B</strong></p><p class="choice_paragraph">II only</p><p><strong>C</strong></p><p class="choice_paragraph">III only</p><p><strong>D</strong></p><p class="choice_paragraph">I and II</p>

A

I only

B

II only

C

III only

D

I and II

A

26
New cards

There are 32 students standing in a classroom. Two different algorithms are given for finding the average height of the students.

Algorithm A

Step 1: All students stand.

Step 2: A randomly selected student writes his or her height on a card and is seated.

Step 3: A randomly selected standing student adds his or her height to the value on the card, records the new value on the card, and is seated. The previous value on the card is erased.

Step 4: Repeat step 3 until no students remain standing.

Step 5: The sum on the card is divided by 32. The result is given to the teacher.

Algorithm B

Step 1: All students stand.

Step 2: Each student is given a card. Each student writes his or her height on the card.

Step 3: Standing students form random pairs at the same time. Each pair adds the numbers written on their cards and writes the result on one student’s card; the other student is seated. The previous value on the card is erased.

Step 4: Repeat step 3 until one student remains standing.

Step 5: The sum on the last student’s card is divided by 32. The result is given to the teacher.

Which of the following statements is true?

Responses

A

Algorithm A always calculates the correct average, but Algorithm B does not.

B

Algorithm B always calculates the correct average, but Algorithm A does not.

C

Both Algorithm A and Algorithm B always calculate the correct average.

D

Neither Algorithm A nor Algorithm B calculates the correct average.

C

27
New cards

The algorithm below is used to simulate the results of flipping a coin 4 times. Consider the goal of determining whether the simulation resulted in an equal number of heads and tails.

Step 1: Initialize the variables heads_counter and flip_counter to 0.

Step 2: A variable coin_flip is randomly assigned a value of either 0 or 1. If coin_flip has the value 0, the coin flip result is heads, so heads_counter is incremented by 1.

Step 3: Increment the value of flip_counter by 1.

Step 4: Repeat steps 2 and 3 until flip_counter equals 4.


Following execution of the algorithm, which of the following expressions indicates that the simulation resulted in an equal number of heads and tails?

Responses

A

coin_flip = 1

B

flip_counter = 1

C

flip_counter = 2

D

heads_counter = 2

D

28
New cards

Consider the following program.

The figure presents four blocks of code that consist of 6 lines. Throughout the third and fourth blocks of code there are nested blocks of code. Line 1: [begin block] val ← 0 [end block] Line 2: [begin block] sum ← 0 [end block] [Begin Block] Line 3: REPEAT 10 TIMES [Begin Block] Line 4: [begin block] val ← val + 2 [end block] Line 5: [begin block] sum ← sum + val [end block] [End Block] [End Block] Line 6: [Begin Block] DISPLAY [begin block] sum [end block] [End Block]

Which of the following describes the result of executing the program?

Responses

A

The program displays the sum of the even integers from 2 to 10.

B

The program displays the sum of the even integers from 2 to 20.

C

The program displays the sum of the odd integers from 1 to 9.

D

The program displays the sum of the odd integers from 1 to 19.

B

29
New cards

The following grid contains a robot represented as a triangle, which is initially facing toward the top of the grid. The robot can move into a white or gray square but cannot move into a black region.

The figure presents a robot in a 7 by 3 grid of squares. The robot is represented by a triangle, which is initially in the top rightmost square, facing left. Black squares represent barriers that the robot cannot pass through. The first row contains black shading in the first, second, and third squares from the left. The second row contains black shading in the first, second, third, fifth, sixth, and seventh squares from the left. The third row contains gray shading in the first square, and black shading in the fifth, sixth, and seventh squares from the left.

Which of the following code segments can be used to move the robot to the gray square?

Responses

A

REPEAT 3 TIMES

{

MOVE_FORWARD()

}

REPEAT 2 TIMES

{

MOVE_FORWARD()

}

REPEAT 3 TIMES

{

MOVE_FORWARD()

}

B

REPEAT 8 TIMES

{

MOVE_FORWARD()

}

C

REPEAT 3 TIMES

{

MOVE_FORWARD()

}

ROTATE_LEFT()

REPEAT 2 TIMES

{

MOVE_FORWARD()

}

ROTATE_LEFT()

REPEAT 3 TIMES

{

MOVE_FORWARD()

}

D

REPEAT 3 TIMES

{

MOVE_FORWARD()

}

ROTATE_LEFT()

REPEAT 2 TIMES

{

MOVE_FORWARD()

}

ROTATE_RIGHT()

REPEAT 3 TIMES

{

MOVE_FORWARD()

}

D

30
New cards

The following grid contains a robot represented as a triangle, which is initially facing right.

The figure presents a robot in a 6 by 6 grid of squares. The robot is represented by a triangle, which is initially in the third square from the left in the fifth row, facing right. The third row contains gray shading in the third square from the left.

The following code segment is intended to move the robot to the gray square.

<MISSING STATEMENT>

{

REPEAT 4 TIMES

{

MOVE_FORWARD()

ROTATE_RIGHT()

}

ROTATE_LEFT()

MOVE_FORWARD()

ROTATE_RIGHT()

}

Which of the following can be used as a replacement for <MISSING STATEMENT> so that the code segment works as intended?

Responses

A

REPEAT 1 TIMES

B

REPEAT 2 TIMES

C

REPEAT 3 TIMES

D

REPEAT 4 TIMES

B

31
New cards
<p><strong>A</strong></p><p><em>y</em> + 3</p><p><strong>B</strong></p><p>3<em>y</em></p><p><strong>C</strong></p><p><strong>D</strong></p><p></p>

A

y + 3

B

3y

C

D

B