Which is the special symbol used in python to add single-line comments?
#
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...
How do you get the length of a list called listname?
len(listname)
Which methods would be used to generate random numbers in Python?
random.randint()
random.uniform()
uniform.random()
random.random()
random.randint()
random.uniform()
random.random()
Which of the following modes is most suitable for writing a binary file in Python?
rb
ab
wb
write-binary
wb
What is the value of c?
a = 3
b = 5
c = a > b
False
staf = True
christal_ball = True
shield = True
sword = False
you_can_pass = staf and christal_ball or sword and shield
True
arr = ['Mug', 'Plate', 'Bowl', 'Saucer', 'Glass']
print(arr[-2])
Saucer
What does this code do?
x = random.randint(1,5)
producing a random integer between 1-5 (inclusive of 1 and 5)
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.?
wa for appending, adding (updating)
x = 5
y = 2
y -=1
print(x, y)
5, 1
def func(n):
if n==1:
return 1
else:
return(n+func(n-1))
print(func(4))
10
arr = ['Mug', 'Plate', 'Bowl', 'Saucer', 'Glass']
arr2 = arr[1:4]
print(arr2)
['Plate', 'Bowl', 'Saucer']
Suggest why a program may be broken down into individual functions.
a. Maintainability. Smaller, simpler functions are easier to maintain.
b. It helps to avoid syntax errors
c. Debugability. It's easier to debug simple functions than complex ones.
d. Non-Descriptive Naming of Variables.
a. Maintainability. Smaller, simpler functions are easier to maintain.
c. Debugability. It's easier to debug simple functions than complex ones.
The open() function opens a file in text format by default. Which mode opens the file in binary format for reading?
rb
r
b
a
rb
Which of the following casts could result in a run time error?
An integer cast as a string
A float cast as a string
An int cast as a float
A string cast as an int
a string cast as an int
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 methods allows to insert a specified value on a specified position? Use the example below for context
list_one = [1, 2, 3]
list_one.method(0, 0)
list_one = [0, 1, 2, 3]
insert()
Which of the following code snippets would be the correct way to import everything from a module
import randint as ra
from random import *
as ra import randint
from random as ra import randint
from random import *
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.
os module
sys module
file module
scikit-learn
scikit-learn
An operation that modifies a variable without making a copy is known as ...
a. in-place operation
b. static typed operation
c. mutability operation
d. constant time operation
a. in-place operation
What is the value of the following code?
Reminder to myself: Conditional #1 picture
6
Which of the following shows the correct way to initialize a single dimension array?
a. arr = []
b. arr = ['Kan', 'Ryne', 'Em']
c. arr = {}
d. arr = [][]
a. arr = []
b. arr = ['Kan', 'Ryne', 'Em']
Which of the following best describes 'sklearn'? Is 'sklearn' a...
a package
an environment
a module
a suite
a package
When creating a text file using the built-in open() function with 'a mode', what will occur if a file is written to a directory which contains a file having the same name?
A duplicate is created with a modified filename
An OS Error
The file is appended to, with the original contents saved
The file is overwritten
The file is appended to, with the original contents saved