🌍 All Study Guides📊 Dashboard📰 Blog💡 About
IBM Applied AI to IBM AI Developer Professional Certificate • STUDY MODE

PRACTICE QUIZ

QUESTION 1 OF 46

What are the most common modes used when opening a file?

A
(a)ppend, (r)edline, (w)rite
B
(a)ppend, (r)ead, (w)riteCorrect Answer
C
(s)ave, (r)ead, (w)rite
D
(a)ppend, (c)lose, (w)rite
QUESTION 2 OF 46

What is the data attribute that will return the title of the file?

A
File1.nameCorrect Answer
B
File1.mode
C
File1.open()
D
File1.close()
QUESTION 3 OF 46

What is the command that tells Python to begin a new line?

A
\b
B
\q
C
\e
D
\nCorrect Answer
QUESTION 4 OF 46

What attribute is used to input data into a file?

A
File1.write()Correct Answer
B
File1.open()
C
File1.read()
D
File1.close()
QUESTION 5 OF 46

What does the attribute name of the file object display ?

A
The name of the fileCorrect Answer
B
The mode of the file
QUESTION 6 OF 46

What is the advantage of using the with statement to open a file

A
it automatically closes the file objectCorrect Answer
B
it saves a backup
QUESTION 7 OF 46

Consider the file object File1 in write mode, what would the following line of code write to the file: File1.write("Hello\n world") world (CORRECT)

A
Hello\n world
B
Hello
C
Hello world
Explanation:

the \n represents a new line PRACTICE QUIZ

QUESTION 8 OF 46

What python object do you cast to a dataframe?

A
set
B
tuple
C
dictionaryCorrect Answer
QUESTION 9 OF 46

How would you access the first-row and first column in the dataframe df?

A
df.ix[0,0]Correct Answer
B
df.ix[0,1]
C
df.ix[1,0]
QUESTION 10 OF 46

What is the proper way to load a CSV file using pandas?

A
pandas.from_csv(‘data.csv’)
B
pandas.load_csv(‘data.csv’)
C
pandas.read_csv(‘data.csv’)Correct Answer
D
pandas.import_csv(‘data.csv’)
QUESTION 11 OF 46

Use this dataframe to answer the question. ( Image S2Q4 ) How would you select the Genre disco? Select all that apply.

A
df.iloc[6, ‘genre’]
B
df.loc[6, 5]
C
df.iloc[6, 4]Correct Answer
D
df.loc[‘Bee Gees’, ‘Genre’]
QUESTION 12 OF 46

Use this dataframe to answer the question. ( Image S2Q5 ) Which will NOT evaluate to 20.6? Select all that apply.

A
df.iloc[4,5]
B
df.iloc[6,5]
C
df.loc[4,’Music Recording Sales’]Correct Answer
D
df.iloc[6, ‘Music Recording Sales (millions)’]Correct Answer
QUESTION 13 OF 46

Use this dataframe to answer the question. ( Image S2Q6 ) How do we select Albums The Dark Side of the Moon to Their Greatest Hits (1971-1975)? Select all that apply. PRACTICE QUIZ

A
df.iloc[2:5, ‘Album’]
B
df.loc[2:5, ‘Album’]Correct Answer
C
df.iloc[2:6, 1]Correct Answer
D
df.loc[2:5, 1]
QUESTION 14 OF 46

What is the Python library used for scientific computing and is a basis for Pandas?

A
Tkinter
B
Requests
C
NumpyCorrect Answer
D
datetime
QUESTION 15 OF 46

What attribute is used to retrieve the number of elements in an array?

A
a.sizeCorrect Answer
B
a.ndim
C
a.shape
D
a.dtype
QUESTION 16 OF 46

How would you change the first element to "10" in this array c:array([100,1,2,3,0])?

A
c[2]=10
B
c[1]=10
C
c[0]=10Correct Answer
D
c[4]=10
QUESTION 17 OF 46

What attribute is used to return the number of dimensions in an array?

A
a.size
B
a.shape
C
a.ndimCorrect Answer
D
a.dtype
QUESTION 18 OF 46

what is the type of the following array: a=np.array([0,1,7,3, 7])

A
int
B
numpy.ndarrayCorrect Answer
QUESTION 19 OF 46

consider the following lines of code: c=np.array([20,1,2,3,4]) c[0]=100 c[0]=2 what is the value of c[0]

A
100
B
20
C
2Correct Answer
QUESTION 20 OF 46

consider the numpy array u how would you multiply each element in the numpy array by 2

A
2*uCorrect Answer
B
[2,2]*u
QUESTION 21 OF 46

how would you perform the dot product between the numpy arrays u and v

A
np.dot(u,v)Correct Answer
B
u*v
QUESTION 22 OF 46

what is the shape of the following array: A=np.array([[1,0,1],[0,1,1]])

A
(2,3)Correct Answer
B
(3,2)
C
6
Explanation:

the first element of the tuple is the number of rows the second is the number of columns

QUESTION 23 OF 46

consider the following array: A=np.array([[1,0,1],[2,2,2]]) what is the value in A[0,1]?

A
0Correct Answer
B
1
C
2
QUESTION 24 OF 46

What is the result of the following operation: Y=np.array([[2,1],[1,2]]) Z=2*Y [2, 4]]) (CORRECT) [2, 2]]) [1, 2]])

A
array([[4, 2],
B
array([[2, 2],
C
array([[2, 1],
Explanation:

multiplying the array by two doubles each element MODULE 4 GRADED QUIZ

QUESTION 25 OF 46

What is the result of the following lines of code? a=np.array([0,1]) b=np.array([1,0]) np.dot(a,b)

A
0Correct Answer
B
1
C
array([1,1])
QUESTION 26 OF 46

What is the value of Z after the following code is run? X=np.array([[1,0],[0,1]]) Y=np.array([[0,1],[1,0]]) Z=X+Y

A
array([[1,1],[1,1]])Correct Answer
B
array([[1,0],[0,1]])
C
array([[0,1],[1,1]])
Explanation:

the '+' corresponds to matrix addition

QUESTION 27 OF 46

What values does the variable out take if the following lines of code are run? X=np.array([[1,0,1],[2,2,2]]) out=X[0:2,2] out Explanation, the first index corresponds to the rows the second index corresponds to the columns

A
array([1,0])
B
array([1,2])Correct Answer
C
array([1,1])
QUESTION 28 OF 46

What do the following lines of code do? with open("Example1.txt","r") as file1: FileContent=file1.readlines() print(FileContent) Explanation, the mode is set to r for read.

A
Read the file "Example1.txt"Correct Answer
B
Write to the file “Example1.txt”
C
Append the file "Example1.txt"
QUESTION 29 OF 46

What do the following lines of code do? with open("Example.txt","w") as writefile: writefile.write("This is line A\n") writefile.write("This is line B\n")

A
Read the file "Example.txt"
B
Write to the file “Example.txt”Correct Answer
C
Append the file "Example.txt"
QUESTION 30 OF 46

What do the following lines of code do? with open("Example3.txt","w") as file1: file1.write("This is line C\n")

A
Read the file "Example3.txt".
B
Append the file "Example3.txt".
C
errorCorrect Answer
Explanation:

There is no indent.

QUESTION 31 OF 46

Consider the dataframe df. How would you access the element in the 2nd row and 1st column?

A
df.iloc[1,0]Correct Answer
B
df.iloc[2,1]
C
df.iloc[0,1]
QUESTION 32 OF 46

In the lab, you learned you can also obtain a series from a dataframe df, select the way to assign the column with the header Length to a pandas series to the variable x.

A
x=df['Length']Correct Answer
B
x=df[['Length']]
C
x=df.[['Length']]
QUESTION 33 OF 46

What is the result of the following lines of code? a=np.array([-1,1]) b=np.array([1,1]) np.dot(a,b)

A
array([0,2])
B
1
C
0Correct Answer
QUESTION 34 OF 46

How do you perform matrix multiplication on the numpy arrays A and B ?

A
A+B
B
A*B
C
np.dot(A,B)Correct Answer
QUESTION 35 OF 46

What values does the variable out take if the following lines of code are run? X=np.array([[1,0,1],[2,2,2]]) out=X[0,1:3] out Explanation, the first index corresponds to the rows the second index corresponds to the columns

A
array([0,1])Correct Answer
B
array([1,0,1])
C
array([2,2])
QUESTION 36 OF 46

What is the value of Z after the following code is run? X=np.array([[1,0],[0,1]]) Y=np.array([[2,2],[2,2]]) Z=np.dot(X,Y) Explanation, the dot function corresponds to matrix multiplication

A
array([[2,2],[2,2]])Correct Answer
B
array([[2,0],[0,2] ])
C
array([[3,2],[2,3]])
QUESTION 37 OF 46

Consider the following text file: Example1.txt: This is line 1 This is line 2 This is line 3 What is the output of the following lines of code? with open("Example1.txt","r") as File1: file_stuff=File1.readline () print(file_stuff) This is line 2 This is line 3 This is line 2

A
This is line 1Correct Answer
B
This is line 1
C
This is line 1
QUESTION 38 OF 46

What task do the following lines of code perform? with open('Example2.txt','r') as readfile: with open('Example3.txt','w') as writefile: for line in readfile: writefile.write(line)

A
Check the mode of the open function for each file object.
B
Copy the text from Example2.txt to Example3.txt.Correct Answer
C
Print out the content of Example2.txt.
QUESTION 39 OF 46

What function would you use to load a csv file in Pandas?

A
pd.read_csvCorrect Answer
B
pd.read_excel
QUESTION 40 OF 46

What is the value of Z after the following code is run? X=np.array([[1,0],[0,1]]) Y=np.array([[2,1],[1,2]]) Z=np.dot(X,Y) Explanation, the dot function corresponds to matrix multiplication

A
array([[2,1],[1,2] ])Correct Answer
B
array([[2,0],[1,0]])
C
array([[3,1],[1,3] ])
QUESTION 41 OF 46

Consider the following line of code: with open(example1,"r") as file1: What mode is the file object in? Explanation, the mode is set to r for read.

A
readCorrect Answer
B
write
C
append
QUESTION 42 OF 46

What do the following lines of code do? with open("Example.txt","a") as writefile: writefile.write("This is line A\n") writefile.write("This is line B\n")

A
Read the file "Example.txt"
B
Append the file "Example.txt"Correct Answer
C
Write to the file “Example.txt”
QUESTION 43 OF 46

Consider the dataframe df. How would you access the element in the 1st row 3rd column

A
df.iloc[2,0]
B
df.iloc[1,3]
C
df.iloc[0,2]Correct Answer
QUESTION 44 OF 46

What method gets the unique elements of the following: df[)Length)] ?

A
uniqueCorrect Answer
B
head
QUESTION 45 OF 46

What values does the variable out take if the following lines of code are run? X=np.array([[1,0,1],[2,2,2]]) out=X[0:2,2] out Explanation, the first index corresponds to the rows the second index corresponds to the columns

A
array([1,0])
B
array([1,2])Correct Answer
C
array([1,1])
QUESTION 46 OF 46

Consider the following text file: Example1.txt: This is line 1 This is line 2 This is line 3 What is the output of the following lines of code? with open("Example1.txt","r") as file1: FileContent=file1.read() print(FileContent) This is line 2 This is line 3 (CORRECT)

A
This is line 1
B
This is line 1

Ready to test your recall?

What are the most common modes used when opening a file?

A
(a)ppend, (r)edline, (w)rite
B
(a)ppend, (r)ead, (w)rite
C
(s)ave, (r)ead, (w)rite
D
(a)ppend, (c)lose, (w)rite

How confident are you in this answer?