1/76
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Which of the following keywords is able to turn a False into a True and is also known as a 'logical inverter'
not
Which of the following modes of file writing would be most appropriate for a program designed to update the contents of a .txt file and to overwrite the entire file if the file contains any data.
w
Suggest why a program may be broken down into individual functions
Reuseability. Encourages code reuse by moving common operations to a separate function.
Debugability. It's easier to debug simple functions than complex ones
.Maintainability. Smaller, simpler functions are easier to maintain.
____ is a programming paradigm that provides a means of structuring programs so that properties and behaviors are bundled into individual objects.
Object-oriented programming
Which of the following modes is most suitable for writing a binary file in Python?
wb
A programmer tries to run the following code. What error is likely to be raised in this instance?
#Example:
print('Hello world')s
syntax error
What is the value of the variable 'a' after it passes through the loops?
a = 0
for i in range(2):
for j in range(3):
a += i + j
9
Which line of code inserted in the program will add a random item from the list each time the loop runs?
import random
option_list = ['candy', 'souvenir', 'gift card', 'stickers', 'book', 'poster']
prize_list = []
for counter in range(3):
# Line of code goes here
prize_list.append(rand_item)
rand_item = random.choice(option_list)
What is the value of the variable 'c' in the following code snippet?
a = 2
b = 1
c = a << b
4
Which of the following best describes the randint function of the random module. Consider the example code below to see the code in context.
x = random.randint(2,5)
producing a random integer between 2-5 (inclusive of 2 and 5)
A data structure that can't be changed after its creation is known as _____?
immutable
Which of the following shows the correct way to initialize a single dimension array?
arr = ['Kan', 'Ryne', 'Em']
arr = []
What is the value returned from this code?
print(type(True))
What is the value of the variable 'c' in the following code snippet?
a = 7
b = 8
c = a ^ b
15
Which of the following modes of file reading would be most appropriate for a program designed to update the contents of a .txt file without making any new deletion to the file.
a
Which methods would be used to generate random numbers in Python?
random.random()
random.randint()
random.uniform()
andom.random()random.randint()random.uniform()
TypeError
What is the type of the variable c in the code snippet?
a = int(3)
b = int('car')
c = a + b
This will raise an error.
What is the value returned from this code?
print(type(4))
Which of the following best describes the randint function of the random module. Consider the example code below to see the code in context.
x = random.randint(1,5)
producing a random integer between 1-5 (inclusive of 1 and 5)
Which of the following best describes 'sklearn'? 'sklearn' (scikit-learn) provides Machine Learning operations and it contains simple and efficient tools for predictive data analysis
a package
A programmer tries to run the following code. What error is likely to be raised in this instance?
#Example:
print(int('cat'))
ValueError
A programmer has created a string with a single speech mark on one side and double speech mark on the other. What error is likely to be raised in this instance?
#Example:
var1 = 'Hello"
syntaxerror
What is the output of the following code?
x = 10
y = 10
z = 0
z = x + y
print(z)
20
An operation that modifies a variable without making a copy is known as ....
in-place operation
Which statement would assign the input.txt file to the handler fin?
fin = open("input.txt", "r")
What is the output from the following print statement?
print(('Trolls :{0} Knights :{1} and {other}').format(45, 55, other='Princesses'))
Trolls :45 Knights :55 and Princesses
A programmer accidentally attempts convert the type of an object and receives the next error: 'int() cannot convert 'dog' into an integer'. What error was likely raised in this instance?
ValueError
What would be the lowest value printed by this code?
for i in range(12):
print(i)
0
What is the result of the following if statement?
def func(j):
if j > 10 and j < 20:
return True
else:
return False
when j is 15 the result is True
when j is 20 the result is False
What is the output of the following code?
x = 10
a = 0
print(x > a)
true
Which of the following casts could result in a run time error?
int("j")
Using the Math module to perform a calculation, what should be output of "math.sqrt(25)"?
5.0
What is the output of the following code?
x, y = 10, 20
min = x if x < y else y
print(min)
10
Match the print statement to it's output?
trolls and knights
knights and trolls
Trolls and "Knights"
Trolls and Knights
What is the output of the following code snippet?
careful = 1
second_chance = True
if careful:
print('I got a second chance at this!')
elif second_chance:
print('I am not being careful...')
else:
print('I am being careful!')
'I got a second chance at this!'
Which of the following lines represents a valid comment?
# print('Content')
Which collection structure allows items that are ordered and changeable and contain duplicate values?
List
Which of the following code snippets would be the correct way to import everything from a module
import randint as ra # Option 1
from random import * # Option 2
as ra import randint # Option 3
from random as ra import randint # Option 4
option 2
What is the value of j after the following calculation?
j = 5 ** 2
25
Which of the following methods allows single items from a list to be deleted and to be returned as individual elements? Use the example below for context.
list_one = [1, 2, 3]
list_one.method()
list_one = [1, 2]
pop()
Consider a program which manages its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer. Which of the following words is suitable for describing the previous program.
Multithreading
What would be the output for the following code?
arr = ['Mug', 'Plate', 'Bowl', 'Saucer', 'Glass']
print(arr[2])
Bowl
Will this program cause an error? If not, what will the value be of you_can_pass?
# possessions
staf = True
christal_ball = True
shield = True
sword = False
you_can_pass = staf and christal_ball or sword and shield
True
Which of the following statements are true?
Python code is structured and indented blocks must be used
What is the value returned from this code?
print(type('?'))
What are Runtime Errors in Python?
Errors that show up when the script is attempting to perform operations on data of the wrong type
Errors that occur because of misspelled or incorrectly capitalized variable and function names
Which of the following keywords is able to turn a True into a False, and is also known as a 'logical inverter'
not
A data structure where the type or the class is less important than the methods it defines is known as what?
duck type
What would be the output of the round() function when this code is evaluated?
x = 1
if(x == 1):
print(round(4.9))
else:
print(round(6.9))
5
What is the output of the following code snippet?
careful = 0
second_chance = True
if careful:
print('I got a second chance at this!')
elif second_chance:
print('I am not being careful...')
else:
print('I am being careful!')
'I am not being careful...'
Which statement would read the entire file contents?
fin.read()
What would be the highest value printed by this code?
for i in range(12):
print(i)
11
Assume you have written your Python code in a separate file named 'myfunctions.py'. Which of the following statements shows the correct syntax for adding it to your new Python script so the code can be used?
import myfunctions
Which of the following best describes 're'? 're' (regular expression) provides regular expression matching operations similar to those found in Perl.
module
How many except statements can a try-except block have?
at least one
Please select the correct answer regarding the following code
v = 'Kim'
x = '{}'.format('Kim')
print(v is x)
Output will be True
Both variables contain string objects
Which collection structure stores items in key value pairs?
dictionary
What is the output of the following code?
x = 5
y = 2
y-=1
print(x, y)
5,1
Which list function returns the number of items contained in the list?
len(listname)
Which collection structure allows items that are ordered, changeable, and does not allow duplicate values?
dictionary
What is the value of the variable 'c' in the following code snippet?
a = 3
b = 5
c = a > b
false
What is the value of the variable 'c' in the following code snippet?
a = 2
b = 1
c = a << b
4
What will happen when the user enters 12?
month_list = ['January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September',
'October', 'November', 'December']
month_number = int(input('Enter the number of your favorite month:')) print('Your favorite month is ' + month_list[month_number] + '!')
There will be an error caused by trying to access index 12
Order these lines of code so that the program checks each item in the list and adds them to the short_pets list if the length of their name is less than 5. Then output the short_pets list.
pet_list = ['cat', 'dog', 'lizard', 'parrot', 'fish', 'turtle'] short_pets = []
for pet in pet_list:
if len(pet) < 5:
short_pets.append(pet)
print(short_pets)
What would be the output for the following code?
arr = ['Mug', 'Plate', 'Bowl', 'Saucer', 'Glass']
arr2 = arr[1:4] print(arr2)
Plate', 'Bowl', 'Saucer'
Whats is the proper shebang to indicate the script is using Python version 3?
#!/usr/bin/env python3
What is the value of the variable 'c' in the following code snippet?
-4
Which code would allocate and initialize a list of 10 integers?
nlist = [0] * 10
Which of the following is used to define a block of code in Python?
indentation
Identify the Python comment.
Comment 3
Which of the following shows the correct way to initialize a multidimensional array?
arr = []
arr = [[]]
Consider the following piece of code. Which of the following is true?
from sklearn.linear_model import LinearRegression
linear_model is a module of sklearn package
Which of the following characters is used for single-line comments in Python?
#
Which of the following methods allows multiple items from a string to be added as individual elements to an existing list? Use the example below for context
list_one = [1,2,3]
string_one = 'abc' list_one.method(string_one)
list_one = [1, 2, 3, 'a', 'b', 'c']
extend()
What is the purpose of the following code?
try: a = int(b) except: print('Error')
Trap an invalid integer value