APCSP - Unit 7 CodeHS Flashcards
Which of the following is the correct way to declare a tuple?
x = (1, 2, 3, )
What is true about tuples?
Tuples are ordered, immutable, and can contain elements of different types.
Which of the following Python programs creates a list with the numbers 1 through 5?
my_list=[1, 2, 3, 4, 5]
What does the following code print?
time_of_day = [“morning”, “afternoon”, “evening”]
for word in time_of_day:
print(“Good “ + word)
Good morning
Good afternoon
Good evening
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’]
my_list.sort()
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’]
my_list.sort()
my_list.reverse()
my_list.remove(“bananas”)
What kind of data structure is user_data in the following declaration?
user_data = (“TJ”, 24, “artLover123”)
Tuple
What kind of data structure is user_data in the following declaration?
user_data = [“TJ”, 24, “artLover123”]
List
What does this code snippet print?
fruit = [“b”, “n”, “n”]
print (“a”.join(fruit))
banan
What is the value of num after this code runs?
shapes = [“triangle”, “square”, “hexagon”, “circle”, “pentagon”]
num = len(shapes)
5
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)
My favorite animal is a penguin or chipmunk
Which of the following data structures is immutable?
Tuple
What does this program print?
heights = [65, 56, 67, 48, 64]
heights.sort()
heights.extend([60, 61, 62])
heights.remove(67)
print (heights)
48, 56, 64, 65, 60, 61, 62
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!”)
4
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)
B
o
n
d
0
0
7