APCSP - Unit 7 CodeHS Flashcards

1
Q

Which of the following is the correct way to declare a tuple?

A

x = (1, 2, 3, )

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

What is true about tuples?

A

Tuples are ordered, immutable, and can contain elements of different types.

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

Which of the following Python programs creates a list with the numbers 1 through 5?

A

my_list=[1, 2, 3, 4, 5]

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

What does the following code print?

time_of_day = [“morning”, “afternoon”, “evening”]
for word in time_of_day:
print(“Good “ + word)

A

Good morning
Good afternoon
Good evening

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

Look at the following program:

my_list = [“bananas”, “oranges”, “grapes”, “pineapples”, “apples”]

You pick the code that goes here…
# …
# …

print(my_list)
Pick the code that results in the following output:

[‘apples’, ‘bananas’, ‘grapes’, ‘oranges’, ‘pineapples’]

A

my_list.sort()

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

Look at the following program:

my_list = [“bananas”, “oranges”, “grapes”, “pineapples”, “apples”]

You pick the code that goes here…
# …
# …

print(my_list)
Pick the code that results in the following output:

[‘pineapples’, ‘oranges’, ‘grapes’, ‘apples’]

A

my_list.sort()
my_list.reverse()
my_list.remove(“bananas”)

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

What kind of data structure is user_data in the following declaration?

user_data = (“TJ”, 24, “artLover123”)

A

Tuple

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

What kind of data structure is user_data in the following declaration?

user_data = [“TJ”, 24, “artLover123”]

A

List

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

What does this code snippet print?

fruit = [“b”, “n”, “n”]
print (“a”.join(fruit))

A

banan

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

What is the value of num after this code runs?

shapes = [“triangle”, “square”, “hexagon”, “circle”, “pentagon”]
num = len(shapes)

A

5

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

What does this program print?

sentence = “My favorite animal is a dog or chipmunk”
sentence_list = sentence.split()
sentence_list[-3] = “penguin”
sentence = “ “.join(sentence_list)
print (sentence)

A

My favorite animal is a penguin or chipmunk

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

Which of the following data structures is immutable?

A

Tuple

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

What does this program print?

heights = [65, 56, 67, 48, 64]
heights.sort()
heights.extend([60, 61, 62])
heights.remove(67)
print (heights)

A

48, 56, 64, 65, 60, 61, 62

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

How many times does this program print That’s a large class!?

num_students = [23, 21, 33, 35, 24, 35]

for num in num_students:
if num > 23:
print (“That’s a large class!”)

A

4

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

What would the following program print to the screen when run?

my_list = [7, 0, 0, “d”, “n”, “o”, “B”]

my_list.reverse()

for thing in my_list:
print (thing)

A

B
o
n
d
0
0
7

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

What will be the output of the following program?

my_list = [1, 2, 3, 4]
num = 5

for index in range(len(my_list)):
my_list.append(num + index)

print (my_list)

A

[1, 2, 3, 4, 5, 6, 7, 8]