UNIT 6 PRACTICE PROBLEMS Flashcards

1
Q

The following algorithm is followed by a person every morning when they get up from bed to go to school:
1. Wake up
2. Brush teeth
3. Put on shirt
4. Put on pants
5. Put on socks
6. Put on shoes
7. Tie shoes
Which concept does this algorithm best demonstrate?

A

Sequencing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following is true of algorithms?

A

Every algorithm can be constructed using combinations of sequencing, selection, and iteration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The algorithm below is used to find the largest element in a list of numbers.
By modifying one of the lines in the program it is possible to make the algorithm find the smallest element. Which line would need to be modified and how?

01 target <- list[1]
02 FOR EACH num IN list
03 {
04 IF(num > target)
05 {
06 target <- num
07 }
08 }
09 DISPLAY(target)

A

Line 04 becomes IF (num < target).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Find the bug. When Button1 is clicked, Label1 is supposed to be set to a name that is selected from the names list by the displayName procedure. But the label’s Text never changes. Why?

a) The displayName procedure is not being called when the button is clicked.
b) The list is not properly set up.
c) The displayName procedure has a bug in it.
d) The displayName procedure was never defined.
e) Maybe Label1 is not enabled.

A

a) The displayName procedure is not being called when the button is clicked.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What value will the global variable name have after Button1 is clicked?

A

Abe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How many elements are there in the names list

A

two elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the length of the following list?

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What value would the global variable name have after the blocks shown here are executed?

A

Mary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What name would be you get if you selected the item at index 2 of the item at index 2 of the names list?

A

Bush

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What name occurs at index 3 in the following list?

A

Barack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What will the following code output read? [song, book, video, book]

A. [“song”, “book”, “read”, “book”]
В. [“song”, “read”, “book”, “video”, “read”, “book”]
C. [“song”, “book”, “read”, “video”, book”, “read”]
D. [‘song”, “readbook”, “video”, “readbook”]

A

B. [“song”, “read”, “book”, “video”, “read”, “book”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What will be displayed once the code is ran?

A

unusual, bold, away

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

People were surveyed whether they preferred cats or dogs.
Preferences were stored in the list animals as strings, with the string “cat” representing a preference for cats and the string
“dog” representing a preference for dogs.
The following code segment is intended to traverse the list and display the number people who prefer cats and the number of people who prefer dogs.

A.
#1: IF (animals = “cats”)
#2: ELSE
B.
#1: IF (response = “cats”)
#2: ELSE
C.
#1: IF (animals = “cats”)
#2: IF (animals = “dogs”)
D. #1: IF (response = “cats”)
#2: IF (response = “dogs”)

A

B. #1: IF (response = “cats”)
#2: ELSE

D. #1: IF (response = “cats”)
#2: IF (response = “dogs”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Names of students who signed up for a club are stored in a list called newMembers. The code segment below is intended to look for a member with a given name stored in a variable called
keyName. The code segment is meant to output the index of the position of the student with keyName. If the name is not in the list, -1 should be displayed.

A. FOR EACH i IN newMembers
B. FOR EACH indexOfName IN newMembers
C. REPEAT n TIMES
D. REPEAT indexOfName TIMES

A

C. REPEAT n TIMES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How many times will the loop be printed? “nom nom”

A

5 times out of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the code’s output?

A

milk