Which list function returns the number of items contained in the list?
a. length(listname)
b. listname.length()
c. listname.len()
d. len(listname)
d. len(listname)
Suggest why a program may be broken down into individual functions
a. Debugability. It's easier to debug simple functions than complex ones.
b. Non-Descriptive Naming of Variables.
c. Reuseability. Encourages code reuse by moving common operations to a separate function.
d. Maintainability. Smaller, simpler functions are easier to maintain.
a. Debugability. It's easier to debug simple functions than complex ones.
c. Reuseability. Encourages code reuse by moving common operations to a separate function.
d. 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.
a. Inheritance
b. Encapsulation
c. Instantiation
d. Object-oriented programming
d. Object-oriented programming
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"
a. SyntaxError
b. EOLerror
c. GrammarError
d. ValueError
a. SyntaxError
Which of the following modes is most suitable for writing a binary file in Python?
a. 'rb'
b. 'write-binary'
c. 'wb'
d. 'ab'
c. 'wb'
What would be the output for the following code?
arr = [[1, 2],[2, 3],[4, 5]]
print(len(arr[0]))
2
Which of the following code snippets would be the correct way to import everything from a module?
from random import * # Option 1 import randint as ra from random # Option 2 import as ra from randint # Option 3 from random as ra import randint # Option 4
from random import * # Option 1
* asterisk = everything
When defining an object with a class, what function is used to establish values of an instance?
a. try()
b. __default__()
c. __init__()
d. Instantiation()
c. __init__()
A programmer tries to run the following code. What error is likely to be raised in this instance?
#Example:
print(int('cat'))a. ValueError
b. GrammarError
c. EOLerror
d. SyntaxError
a. ValueError
A programmer wants to use simple and efficient tools for predictive data analysis that are used for Machine Learning. Suggest a suitable module or package that could be used to check for this task.
a. sys module
b. file module
c. os module
d. scikit-learn
d. scikit-learn
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()
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)
a. producing a random integer between 2-5 (inclusive of 2 and 5)
b. producing a random integer between 2-5 (excluding 2 and 5)
c. producing a random float between the values of 2 and 5 (inclusive of 2 and 5)
d. producing between 2 to 5 individual random integers
a. producing a random integer between 2-5 (inclusive of 2 and 5)
Which statement would indicate that the D3Point class inherits characteristics from the Point class?
a. Class D3Point(“Point”):
b. Class D3Point(Point):
c. class D3Point(Point):
d. class D3Point(“Point”):
c. class D3Point(Point):
A programmer accidentally attempts to call a function or use an operator on something of the incorrect type. What error is likely to be raised in this instance?
a. AttributeError
b. ValueError
c. NameError
d. TypeError
d. TypeError
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. a
B. w
C. re
D. r
A. a
a = append
append means to add
Which of the following shows the correct way to initialize a multidimensional array?
a. arr = ['Jack'].extend(['Kan','Ryne','Ema'])
b. arr = [][]
c. arr = []
d. arr = [[]]
d. arr = [[]]
The pip command line utility allows the developer to install ________?
a. Python modules
b. Python packages
c. Invalid
d. Python libraries
b. Python packages
A programmer has created a class to represent Employees, and each employee has a unique name, role and ID number. The programmer also wants to create a special method to overload the len() method such that every Employee instance will return the seniority in the company. What is best to use for this situation?
a. An instance attribute
b. A class attribute
c. A property decorator
d. A dunder method
d. A dunder method
A programmer accidentally attempts to 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?
a. TypeError
b. AttributeError
c. ValueError
d. NameError
c. ValueError
A developer wants to read a text file but he is unsure if the file exists in the current directory. Suggest a suitable module that could be used to check for the presence of the file in the current working directory.
a. sys module
b. re module
c. os module
d. file module
c. os module
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)
A programmer wants to match a specific string using a regular expression. What would be most appropriate to match the following string? 'Hello NAME'. The 'NAME' can be any 4 letter name containing only letters, such as 'Hi Alex', or 'Hi John'.
A. r'hi\w{4}'
B. r'Hi \d\d\d\d'
C. r'Hi \w{4}'
D. r'Hi \W{4}''
C. r'Hi \w{4}'
See Classes, Objects, and OOP 500 image
___def calc(self):
___________return self.x * self.y
The underscores are just make it look like it's indented correctly; they are not part of the answer!
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.
a. A module callback
b. A request loop
c. A chapter
d. Multithreading
d. Multithreading
A programmer wants to use various functions and variables that are used to manipulate different parts of the Python runtime environment. Suggest a suitable module that could be used to check for this task.
a. sys module
b. re module
c. os module
d. file module
a. sys module