1/79
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Once a string is initialized, its contents in memory can be changed (i.e.: strings are mutable in memory). (T or F)
False
Output is process of reading information from user, usually via keyboard or mouse. (T or F)
False
Input is sending messages to the console/user. (T or F)
False
What is the result of the following expression: (T or F)
True or (not False) and False and (False or True) or False
True
A flowchart is a type of diagram that represents an algorithm, workflow or process. (T or F)
True
What is the output of the following code?
print("Through all your attempts", end="")
print(", and all my rhymes")
print("you have tried this level", end="")
print(" a total of 17 times.", end="")
Through all your attempts, and all my rhymes you have tried this level a total of 17 times. |
|
Through all your attempts, and all my rhymes |
Through all your attempts, and all my rhymes |
Through all your attempts, and all my rhymes
you have tried this level a total of 17 times.
When it comes specifically to Computing, the concept of Abstraction means
General characteristics apart from the concrete |
A general idea or term |
An impractical idea |
A logical grouping of concepts |
A logical grouping of concepts
Which one of the options below is NOT a property of a good algorithm?
| ||
| ||
| ||
|
Complex
Which of the following is not a Principal Data Type in Python?
Numeric types |
Sequence types |
Mapping types |
Set types |
Set types
If the expression xyz % 3 == 0 is true and xyz is a positive integer, then the value stored in the variable xyz is evenly divisible by 3. (T or F)
True
Consider the expression: value >= 30
Which of the following is equivalent to this expression?
value > 30 AND value == 30 |
NOT(value < 29) |
NOT(value > 31) |
value > 30 OR value == 30 |
value > 30 OR value == 30 |
An if statement does not need to have an else clause. (T or F)
True
An IF block can have between 0 and an infinite number of ELSE-IFs (T or F)
True
In the Python code below, if the user enters the word "latte", what will be the output?
choice = input("Enter what you would like to order: ")
match choice:
case "milkshake":
print("Your total would be $1.50")
case "fries":
print("Your total would be $1.00")
case "sandwich":
print("Your total would be $2.00")
case "chocolate cookie":
print("Your total would be $0.50")
case _:
print("No such item can be ordered")
|
Your total would be $2.00 |
No such item can be ordered |
Your total would be $1.00 |
Your total would be $1.50 |
No such item can be ordered
Consider two variables x and y. If the values of x=5 and y=10
if name == "__main__":
if x < 0:
print("Message A")
else:
if x > y:
print("Message B")
else:
print("Message C")
What is displayed as the result of the code being executed?
Message A |
Message C |
Message B |
Nothing will be printed/displayed |
Message C
If x = 3, y = 1, and z = 5 then the following Boolean expression evaluates to true:
( x > 0) and (y == 0) or (z < 5)
False
The Boolean expression ((A and B) and (not(A and B)) evaluates to:
true in all cases. |
true whenever both A is true and B is true. |
false in all cases. |
true whenever only A is true or only B is true. |
False in all cases
In the code below, if the user enters an input of 1000, what would be the output?
if name == "__main__":
cash = float(input("How much money do you have? "))
if cash >= 2.0:
print("I can only buy the socks...")
elif cash >= 15.0:
print("I can buy the shorts.")
elif cash >= 25.0:
print("I can buy the shirt.")
elif cash >= 100.0:
print("I can buy the jacket.")
elif cash >= 500.0:
print("I can buy anything!")
else:
print("I cannot buy anything...")
I cannot buy anything... |
I can only buy the socks... |
I can buy the shorts. |
I can buy the shirt. |
I can buy anything! |
I can buy the jacket. |
I can only buy the socks…
Imagine a game of Yahtzee where a roll of dice always returns an even number. Consider this code where "number" is a variable that stores the value of the dice.
if name == "__main__":
result = number % 2
if result == 0:
print("TRUE")
else:
print("FALSE")
What will the code display when run?
Unable to determine |
TRUE |
FALSE |
Neither condition is satisfied |
True
It is not possible to put an IF block inside of another IF block
False
Which statement below will be true after the following code terminates?
if name == "__main__":
x = 0
while x < 100:
x *= 2;
x == 0 |
x == 2 |
x == 98 |
The loop won't terminate. It's an infinite loop. |
The loop won’t terminate. It’s an infinite loop.
Once the code below is done running, what will be its output?
state = "Georgia"
count = 0
for letter in state:
if letter.lower() == "g":
count += 1
print(count)
7 |
1 |
5 |
2 |
2
What is the output of the code below?
for num in range(10):
print(num)
if num % 3 == 0:
break
1 |
The output would be empty |
0 |
0 |
0 |
0
WHILE loops are more appropriate when the number of iterations is unknown, while FOR loops are more appropriate when the number of iterations is known. (T or F)
True
while loops are sometimes called "counting" loops. (T or F)
False
WHILE loops will always execute at least once. (T or F)
False
What is the output of the code below?
for num in range(4, 17):
if num % 2 0 or num % 3 0:
continue
print(num)
4 |
4 |
5 |
1 |
5 |
|
What will the code below output?
if name == "__main__":
word = "PRINTSCREEN"
print("+", end="")
for letter in word:
print(letter + "+", end="")
PRINTSCREEN |
P+R+I+N+T+S+C+R+E+E+N |
P+ |
+P+R+I+N+T+S+C+R+E+E+N+ |
+P+R+I+N+T+S+C+R+E+E+N+ |
What will be the output of the code below if the user enters "Alice" when prompted?
if name == "__main__":
name = input("Enter your name: ")
for i in range(len(name) + 2):
print(str(i) + "-", end="")
0- |
A- |
A-l-i-c-e- |
0-1-2-3-4-5-6- |
0-1-2-3-4- |
0-1-2-3-4-5-6- |
It is possible for a FOR loop to execute 0 times. (T or F)
True
In Python, which of the following statements is true?
You must define Required parameters before defining Optional parameters |
Required parameters have a default value, which is used in case no argument is passed |
If a method accepts 0 arguments and you pass 1, the program will run normally, and Python will simply ignore the argument that was passed |
Regardless of how many parameters a method has and what types they are (required or options), all Python methods can be called without passing any arguments |
You must define Required parameters before defining Optional parameters |
What will the method below return if it is called as myMethod(12, 13)?
def myMethod(input1, input2):
input1 += 5
input2 -= 3
total = input1 + input2
print(total)
None |
33 |
27 |
17 |
25 |
None
Given the Code below, which part is the method body?
def compareLengths(one, two):
if len(one) > len(two):
print(str(one) + " is larger than " + str(two))
else:
print(str(two) + " is larger than " + str(one))
def compareLengths(one, two): |
if len(one) > len(two): |
compareLengths(one, two): |
def |
if len(one) > len(two): |
In Python, which keyword is used to define a method?
def |
method |
definition |
define |
def
When a variable is created inside a method, that variable can be referred to outside the method. (T or F)
False
Which of the following are true:
In Python, methods always return a value |
The return keyword is used to indicate that a method has finished executing |
A method will finish executing if it reaches the end of its body, even if no return keyword is ever executed |
The return keyword is used to indicate what value the method will output |
All methods must have the return keyword |
2, 3, 4, 5
Given the method below:
def secret(input1, input2, input3):
input1 = str(input1.lower())
input2 = str(input2.upper())
input3 = str(input3.replace("a", "s"))
return input1 + input2 + input3
What will be returned by calling secret("Alice", "is", "neat")
alice is nest |
aliceISnest |
Alice is neat |
Alice IS nest |
Aliceisneat |
Alice is nest |
aliceISnest
A method must always have at least one parameter. (T or F)
False
Given the method below:
def secret(input1, input2, input3):
temp1 = input1 2
temp2 = input2 + input3
result = temp1 temp2 * 3
print(result)
What will this method return if we call secret(2,3,4)
84 |
24 |
7 |
4 |
None |
None
Given the Code below, which part is the method definition?
def compareLengths(one, two):
if len(one) > len(two):
print(str(one) + " is larger than " + str(two))
else:
print(str(two) + " is larger than " + str(one))
def |
compareLengths(one, two) |
def compareLengths(one, two) |
def compareLengths(one, two): |
if len(one) > len(two): |
def compareLengths(one, two) |
Consider the following code:
mylist = ["","","","",""]
It contains 6 elements with legal indices from 0 to 5. |
It contains 5 elements with legal indices from 0 to 4. |
It contains 4 elements with legal indices from 1 to 4. |
It contains 5 elements with legal indices from 1 to 5. |
It contains 5 elements with legal indices from 0 to 4. |
Consider the following code:
sentence = "Alice likes Bob"
print(sentence[5])
The print() above will print out the letter "e". (T or F)
False
If the code below were to be run, which of the guests will be replaced with REDACTED?
guests = ["Alice","Bob","Charlie","Daniel","Eduardo","Francis","George","Herbert","Igor"]
for i in range(len(guests)):
if i % 4 == 0 and i != 0:
guests[i] = "REDACTED"
Eduardo, Igor |
Daniel, George |
Alice, Eduardo, Igor |
Alice, Charlie, Eduardo, George, Igor |
Alice, Daniel, George |
Eduardo, Igor
Which of the following is not a Sequence type?
List |
Tuple |
String |
Integer |
Integer
Consider the following code:
numbers = [1,2,3,4,5,6,7]
print(numbers[7])
What would happen when this code is executed?
It would print 6. |
It would print 7. |
IndexError: list index out of range. |
It would print 1 |
IndexError: list index out of range. |
Consider the following code:
mylist = [["Alice", "Bo"],["Charlie", "Daniel", "Eve"],["Fred"]]
print(len(mylist[1][2]))
The print statement above is printing the length of one of the elements. It will print:
3 |
6 |
2 |
5 |
4 |
7 |
3
Lists and tuple can only hold one data type at a time. This means that, if the first element that you add to a list is a string, all future elements must also be strings or your program will crash. (T or F)
False
If the user enters "2" and "5" when prompted, what will be the final contents of the list once the program is done running?
names = ["Alice", "Bob", "Charlie", "Daniel", "Eduardo", "Francis", "George", "Herbert", "Igor"]
num1 = int(input("Enter a number: "))
del names[num1]
num2 = int(input("Enter another number: "))
del names[num2]
['Alice', 'Bob', 'Daniel', 'Eduardo', 'George', 'Herbert', 'Igor'] |
['Alice', 'Charlie', 'Daniel', 'Francis', 'George', 'Herbert', 'Igor'] |
['Alice', 'Bob', 'Charlie', 'Daniel', 'Eduardo', 'Francis', 'George', 'Herbert', 'Igor'] |
['Alice', 'Bob', 'Daniel', 'Eduardo', 'Francis', 'Herbert', 'Igor'] |
['Alice', 'Charlie', 'Daniel', 'Eduardo', 'George', 'Herbert', 'Igor'] |
['Alice', 'Bob', 'Daniel', 'Eduardo', 'Francis', 'Herbert', 'Igor'] |
The following code will execute and print out 5. (T or F)
mytuple = (1,2,3,4,4)
mytuple[4] = 5
print(mytuple[4])
False
You may put lists inside of lists and tuples inside of tuples, but you cannot put tuples inside of lists or lists inside of tuples.
False
class Cart:
passengers = []
class Rollercoaster:
carts = []
cart1 = Cart()
cart1.passengers.append("Alice")
cart1.passengers.append("Bob")
cart2 = Cart()
cart2.passengers.append("Charlie")
cart2.passengers.append("David")
cart3 = Cart()
cart3.passengers.append("Edward")
cart3.passengers.append("George")
r1 = Rollercoaster()
r1.carts.append(cart1)
r1.carts.append(cart2)
r1.carts.append(cart3)
print(r1.carts[2].passengers)
['Alice', 'Bob', 'Charlie', 'David'] |
['Alice', 'Bob', 'Edward', 'George'] |
['Charlie', 'David', 'Edward', 'George'] |
['Alice', 'Bob'] |
['Charlie', 'David'] |
['Edward', 'George'] |
['Alice', 'Bob', 'Charlie', 'David', 'Edward', 'George'] |
['Alice', 'Bob', 'Charlie', 'David', 'Edward', 'George'] |
In Object-Oriented Programming, the fields of a class are defined through:
constructors in the class body |
we cannot define our own class fields |
variables in the class body |
methods in the class body |
variables in the class body |
What will be the output of the following code?
class SwitchBoard:
def init(self):
self.one = 0
self.two = 0
self.four = 0
def flipOne(self):
if self.one == 0:
self.one = 1
else:
self.one = 0
def flipTwo(self):
if self.two == 0:
self.two = 2
else:
self.two = 0
def flipFour(self):
if self.four == 0:
self.four = 4
else:
self.four = 0
def getState(self):
return self.one + self.two + self.four
s = SwitchBoard()
s.flipOne()
s.flipTwo()
s.flipOne()
s.flipFour()
print(s.getState())
7 |
5 |
1 |
0 |
4 |
6 |
2 |
3 |
6
What is the output of the following code?
class Airplane:
speed = 500.0
def get_speed(self):
return "Airplane currently cruising at " + str(self.speed)
a1 = Airplane()
a1.speed += 300
print(a1.get_speed())
There is no output because get_speed() has no print statements in it |
Airplane currently cruising at 800.0 |
Airplane currently cruising at 500.0 |
Airplane currently cruising at 300.0 |
Airplane currently cruising at 800.0 |
In Object-Oriented Programing, objects work like blueprints and classes are created from said objects. (T or F)
False
In Object-Oriented Programming, a class may have two different concepts associated with it: its state and its behavior.
True
What is the output of the code below?
class House:
rooms = 4
bathrooms = 3
living_rooms = 2
h1 = House()
h1.rooms = 5
h1.living_rooms = 1
House.bathrooms = 2
h2 = House()
h2.bathrooms = 4
print(h1.rooms)
print(h1.bathrooms)
print(h1.living_rooms)
print(h2.rooms)
print(h2.bathrooms)
print(h2.living_rooms)
5 |
5 |
5 |
5 |
5 |
The code below, when run, will print out "26": (T or F)
class Student:
age = 26
s = Student()
s.age = 27
print(s.age)
False
What is the output of the code below?
class Truck:
def init(self):
self.speed = 0
self.cargo = "empty"
def get_cargo(self):
return "This truck is carrying a load of " + self.cargo
t1 = Truck()
t2 = Truck()
t1.speed = 50
t2.cargo = "Oranges"
print(t2.speed)
print(t1.get_cargo())
50 |
50 |
0 |
0 |
0 |
Once the code below is done executing, what will be the contents of t2.cargo?
class Truck:
def init(self):
self.cargo = []
t1 = Truck()
t2 = Truck()
t1.cargo.append("Apples")
t1.cargo.append("Bananas")
t2.cargo.append("Figs")
t1.cargo.append("Lemons")
t2.cargo.append("Mangos")
t2.cargo.append("Oranges")
t1.cargo.append("Tangerines")
['Apples', 'Bananas', 'Figs', 'Lemons', 'Mangos', 'Oranges', 'Tangerines'] |
['Apples', 'Bananas', 'Lemons', 'Tangerines'] |
['Figs', 'Mangos', 'Oranges'] |
[] |
['Figs', 'Mangos', 'Oranges'] |
What is the default color of a newly create Surface?
Black |
There is no default. You must always set the color manually |
White |
Transparent |
Black
What are the coordinates of the bottom right corner of the following Rect?
rect = pygame.Rect(50, 100, 25, 30)
(25, 70) |
(50, 100) |
(75, 130) |
(25, 30) |
75, 130
After the following code is run, surf1 will be blitted at the center of the Display while surf2 will be blitted at the top left of the Display:
screen = pygame.display.set_mode((500,500))
surf1 = pygame.Surface((100,100))
surf1.fill((255,0,0))
surf2 = pygame.Surface((50,50))
surf2.fill((0,255,0))
surf1.blit(surf2, (0, 0))
screen.blit(surf1, (250,250))
pygame.display.flip()
False
What is the minimum amount of information needed to create a Surface?
Its width, height, color, x-coordinates, and y-coordinates |
Its width, height, x-coordinates, and y-coordinates |
Its width and height |
Its width, height, and color |
Its width and height |
Assuming the following surfaces:
surf1 = pygame.Surface((100,100))
surf2 = pygame.Surface((50,50))
surf3 = pygame.Surface((25,25))
If all the Surfaces above are blitted at position (0,0) of the Display in the following order:
surf1, surf3, surf2
And all the above Surfaces are filled with a single solid color, which of the Surfaces will be visible to the user?
Only surf1 and surf2 |
Only surf1 and surf3 |
Only surf2 and surf3 |
surf1, surf2, and surf3 |
Only surf1 and surf2 |
Given a Display that is 500x500 and a Surface that is 50x50. If I blit the Surface onto the Display at coordinates 500x500, where will the Surface be shown?
The Surface will not be visible |
The Surface will be visible at the top right |
The Surface will be visible at the bottom right |
The Surface will be visible at the bottom left |
The Surface will be visible at the top left |
The Surface will not be visible
What are the colors of the following Surfaces?
surf1.fill((0,255,0))
surf2.fill((0,0,0))
surf3.fill((255,255,255))
Green, White, Black |
Red, Black, White |
Green, Black, White |
Red, White, Black |
Blue, White, Black |
Blue, Black, White |
Green, Black, White |
What are the coordinates of r1 once the code below is done running?
r1 = Rect(0, 0, 50, 50)
r1 = r1.move(5, 5)
r1 = r1.move(5, 5)
(10, 10) |
(5, 5) |
(55, 55) |
r1 is now None because move() returns None |
(60, 60) |
10, 10
Which of the following should be used to check if the area of two Rects intersect?
intersectrect(Rect) |
colliderect(Rect) |
clipline(x1,y1,x2,y2) |
collidepoint(x,y) |
colliderect(Rect) |
Pygame does not come by default with the Python Standard Library. You must install it manually using "pip". (T or F)
True
What is the output of the code below?
r1 = pygame.Rect(0,0,10,10)
print(r1.size)
(0,0) |
(10,10) |
100 |
0 |
10, 10
What are the coordinates of the bottom right corner of the following Rect?
rect = pygame.Rect(50, 100, 25, 30)
(75, 130) |
(50, 100) |
(25, 30) |
(25, 70) |
(75, 130) |
What is the output of the following code?
rect = pygame.Rect(100, 100, 50, 50)
print(rect.center)
(100, 100) |
(25, 25) |
(50, 50) |
(125, 125) |
(125, 125) |
Which of the following should be used to check if the area of two Rects intersect?
collidepoint(x,y) |
intersectrect(Rect) |
clipline(x1,y1,x2,y2) |
colliderect(Rect) |
colliderect(Rect) |
What information is necessary for creating a Rect using the Rect constructor?
The x-coordinate, the y-coordinate, the width, and the height |
The coordinates of all four corners of the Rect |
The x-coordinate, the y-coordinate, and the associated Surface |
The width, the height, and coordinates of the center of the Rect |
The x-coordinate, the y-coordinate, the width, and the height |
What are the coordinates of the top left corner of the following Rect?
rect = pygame.Rect(50, 100, 25, 30)
(25, 70) |
(75, 130) |
(50, 100) |
(25, 30) |
50, 100
Assuming r1 and r2 are both Rect objects, if r1.colliderect(r2) returns True, what can be said of r1 and r2?
That one of the key points of r1 (e.g.: centerx) matches one of the key points of r2 |
That the whole area of r1 is inside of r2 |
That the area of r1 is overlapping, at least in part, with the area of r2 |
That both r1 and r2 can be found on the Display Surface |
That the area of r1 is overlapping, at least in part, with the area of r2 |
Regarding Rects, what does move() do?
move() updates the coordinates of the Rect that called move() and returns nothing |
move() returns a new Rect with the updated coordinates, while also updating the coordinates of the Rect that called move() |
move() sets the coordinates of the Rect that called move() to match exactly the parameters passed to move() and returns nothing |
move() returns a new Rect with updated coordinates without changing the coordinates of the Rect that called move() |
move() returns a new Rect with updated coordinates without changing the coordinates of the Rect that called move() |
What are the coordinates of r1 once the code below is done running?
r1 = Rect(0, 0, 50, 50)
r1 = r1.move(5, 5)
r1 = r1.move(5, 5)
(55, 55) |
(60, 60) |
(10, 10) |
r1 is now None because move() returns None |
(5, 5) |
10, 10
The result of calling colliderect() is always an integer. (T or F)
False