[Coursera] Python for Data Science, AI & Development
Coursera / IBM Professional Certificate / Data Science
2021.08.29.

Quiz


πŸ“Œ What is the result of the following operation:

11//2
  • 5.5
  • 5


πŸ“Œ What is the value of x after the following is run:

x=4
x=x/2 
  • 4.0
  • 2.0


πŸ“Œ What is the output of the following:

print("AB\nC\nDE")
  • ABC
    DE
  • AB
    CD
    E
  • AB
    C
    DE


πŸ“Œ What is the result of following?
If you are unsure, copy and paste the code into Jupyter Notebook and check.

"hello Mike".find("Mike") 
  • 6
  • 6, 7, 8
  • 5


πŸ“Œ What is the value of x after the following lines of code?

x=2
x=x+2
  • 4
  • 2


πŸ“Œ What is the result of the following operation:

3+2*2
  • 3
  • 7
  • 9


πŸ“Œ What is the result of the following code segment:

type(int(12.3))
  • int
  • str
  • float


πŸ“Œ What is the result of the following code segment:

int(False)
  • 1
  • 0
  • error


πŸ“Œ In Python, what is the result of the following operation:

'1'+'2'
  • 3
  • β€˜3’
  • β€˜12’


πŸ“Œ Given myvar = 'hello', how would you return myvar as uppercase?

  • len(myvar)
  • myvar.find(β€˜hello’)
  • myvar.upper()


πŸ“Œ What is the result of the following:

str(1)+str(1)
  • β€˜11’
  • 2


πŸ“Œ What is the result of the following:

"ABC".replace("AB", "ab")
  • β€˜abC’
  • β€˜ABc’


πŸ“Œ In Python 3, what is the type of the variable x after the following:

x=2/2
  • float
  • int


πŸ“Œ Consider the following tuple:

say_what=('say',' what', 'you', 'will') 

what is the result of the following say_what[-1]

  • β€˜will’
  • β€˜say’
  • ’ what’
  • β€˜you’


πŸ“Œ Consider the following tuple A=(1,2,3,4,5). What is the result of the following:

A[1:4]
  • (3, 4,5)
  • (2, 3, 4,5)
  • (2, 3, 4)


πŸ“Œ Consider the following tuple A=(1,2,3,4,5), what is the result of the following:

len(A)
  • 6
  • 5
  • 4


πŸ“Œ Consider the following list B=[1,2,[3,'a'],[4,'b']], what is the result of the following:

B[3][1]
  • β€œc”
  • [4,β€œb”]
  • β€œb”


πŸ“Œ What is the result of the following operation?

[1,2,3]+[1,1,1]
  • TypeError
  • [1, 2, 3, 1, 1, 1]
  • [2,3,4]


πŸ“Œ What is the length of the list A = [1] after the following operation:

A.append([2,3,4,5])
  • 2
  • 6
  • 5


πŸ“Œ What is the result of the following:

"Hello Mike".split()
  • [β€œH”]
  • [β€œHelloMike”]
  • [β€œHello”,β€œMike”]


πŸ“Œ What are the keys of the following dictionary:

{"a":1,"b":2}
  • 1,2
  • β€œa”,β€œb”


πŸ“Œ Consider the following Python Dictionary: Dict={"A":1,"B":"2","C":[3,3,3],"D":(4,4,4),'E':5,'F':6} What is the result of the following operation:

Dict["D"]
  • (4, 4, 4)
  • [3,3,3]
  • 1


πŸ“Œ Consider the following set: {"A","A"}, what will the result be when the set is created?

  • {β€œA”}
  • {β€œA”,β€œA”}


πŸ“Œ What is the result of the following:

type(set([1,2,3]))
  • set
  • list


πŸ“Œ What method do you use to add an element to a set?

  • append
  • add
  • Extend


πŸ“Œ What is the result of the following operation:

{'a', 'b'} &{'a'}
  • {β€˜a’, β€˜b’}
  • {β€˜a’}


πŸ“Œ Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation

A[1]
  • ((11,12),[21,22])
  • (11,12)
  • [21,22]


πŸ“Œ Consider the tuple A=((1),[2,3],[4]), that contains a tuple and list. What is the result of the following operation

A[2][0]
  • 4
  • [4]
  • 1


πŸ“Œ True or false: after applying the following method, L.append(['a','b']), the following list will only be one element longer.

  • True
  • False


πŸ“Œ Consider the following list A=["hard rock", 10, 1.2] What will list A contain affter the following command is run:

del(A[1])
  • [10,1.2]
  • [β€œhard rock”,1.2]
  • [β€œhard rock”,10]


πŸ“Œ What is the syntax to clone the list A and assign the result to list B ?

  • B=A
  • B=A[:]


πŸ“Œ Consider the following dictionary:

{ "The Bodyguard":"1992", "Saturday Night Fever":"1977"}

select the values:

  • β€œ1977”
  • β€œ1992”
  • β€œThe Bodyguard”
  • β€œSaturday Night Fever”


πŸ“Œ The variable release_year_dict is a Python Dictionary, what is the result of applying the following method:

release_year_dict.values()
  • retrieve the keys of the dictionary
  • retrieves, the values of the dictionary


πŸ“Œ Consider the Set: V={'A','B'}, what is the result of V.add('C')?

  • {β€˜A’,β€˜B’,β€˜C’}
  • {β€˜A’,β€˜B’}
  • error


πŸ“Œ What is the result of the following:

'1' in {'1','2'}
  • False
  • True


πŸ“Œ what is the result of the following:

1=2
  • SyntaxError:can’t assign to literal
  • False
  • True


πŸ“Œ What is the output of the following code segment:

i=6
i<5 
  • True

  • False

  • SyntaxError: can’t assign to literal


πŸ“Œ What is the result of the following:

5!=5
  • False
  • True


πŸ“Œ What is the output of the following code segment:

'a'=='A'
  • False
  • True


πŸ“Œ in the video, if age=18 what would be the result

  • move on
  • you can enter


πŸ“Œ in the video what would be the result if we set the variable age as follows:

age= -10
  • go see Meat Loaf
    move on
  • you can enter
    move on


πŸ“Œ what is the result of the following: True or False

  • True, an or statement is only False if all the Boolean values are False
  • False


πŸ“Œ what will be the output of the following:

for x in range(0,3):     
    print(x) 
  • 0
    1
    2
  • 0
    1
    2
    3


πŸ“Œ what is the output of the following:

for x in ['A','B','C']:
    print(x+'A') 
  • AA
    BA
    CA
  • A
    B
    C


πŸ“Œ what is the output of the following:

for i, x in enumerate(['A','B','C']):    
    print(i, x) 
  • 0 A
    1 B
    2 C
  • AA
    BB
    CC


πŸ“Œ What does the following function return:

len(['A','B',1])
  • 3
  • 2
  • 4


πŸ“Œ What does the following function return:

len([sum([0,0,1])])
  • 1
  • 0
  • 3


πŸ“Œ What is the value of list L after the following code segment is run :

L=[1,3,2]
sorted(L) 
  • L:[1,3,2]
  • L:[1,2,3]
  • L:[0,0,0]


πŸ“Œ From the video what is the value of c after the following:

c=add1(2)
c=add1(10) 
  • 3

  • 11

  • 14


πŸ“Œ what is the output of the following lines of code:

def Print(A):   
    for a in A: 
        print(a+'1')

Print(['a','b','c']) 
  • a
    b
    c
  • a1
    b1
    C1
  • a1


πŸ“Œ Why do we use exception handlers?

  • Catch errors within a program
  • Read a file
  • Write a file
  • Terminate a program


πŸ“Œ What is the purpose of a try…except statement?

  • Executes the code block only if a certain condition exists
  • Crash a program when errors occur
  • Catch and handle exceptions when an error occurs
  • Only executes if one condition is true


πŸ“Œ What is the type of the following?

["a"] 
  • str

  • list


πŸ“Œ What does a method do to an object?

  • Changes or interacts with the object
  • Returns a new values


πŸ“Œ We create the object:

Circle(3,'blue')

What is the color attribute set to?

  • 2
  • β€˜blue’


πŸ“Œ What is the radius attribute after the following code block is run?

RedCircle=Circle(10,'red')
RedCircle.radius=1 
  • 10
  • 1
  • β€˜red’


πŸ“Œ What is the radius attribute after the following code block is run?

BlueCircle=Circle(10,'blue')
BlueCircle.add_radius(20) 
  • 10
  • 20
  • 30


πŸ“Œ What is the output of the following code?

x="Go"
if(x=="Go"):
  print('Go ')
else:
  print('Stop')
print('Mike')
  • Go Mike
  • Mike
  • Stop Mike


πŸ“Œ What is the result of the following lines of code?

x=1
x>-5
  • True
  • False


πŸ“Œ What is the output of the following few lines of code?

x=5
while(x!=2):
  print(x)
  x=x-1
  • 5
    4
    3
  • 5
    4
    3
    2
  • the program will never leave the loop


πŸ“Œ What is the result of running the following lines of code ?

class Points(object):
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def print_point(self):
        print('x=',self.x,' y=',self.y)

p1=Points(1,2)
p1.print_point()
  • x=1;

  • x=1 y=2

  • y=2


πŸ“Œ What is the output of the following few lines of code?

for i,x in enumerate(['A','B','C']):
    print(i+1,x)
  • 1 A
    2 B
    3 C
  • 0 A
    1 B
    2 C
  • 0 AA
    1 BB
    2 CC


πŸ“Œ What is the result of running the following lines of code ?

class Points(object):
    def __init__(self,x,y):
        self.x=x
        self.y=y
    def print_point(self):
        print('x=',self.x,' y=',self.y)

p2=Points(1,2)
p2.x=2
p2.print_point()
  • x=2 y=2
  • x=1 y=2
  • x=1 y=1


πŸ“Œ Consider the function delta, when will the function return a value of 1?

def delta(x):
    if x==0:
        y=1
    else:
        y=0
    return(y)
  • When the input is anything but 0
  • When the input is 1
  • Never
  • When the input is 0


πŸ“Œ What is the output of the following lines of code?

a=1

def do(x):
    a=100
    return(x+a)

print(do(1))
  • 2
  • 101
  • 102


πŸ“Œ Write a function name add that takes two parameter a and b, then return the output of a + b (Do not use any other variable! You do not need to run it. Only write the code about how you define it.)

def add(a, b):
    return a + b


πŸ“Œ Why is it best practice to have multiple except statements with each type of error labeled correctly?

  • Ensure the error is caught so the program will terminate
  • In order to know what type of error was thrown and the location within the program
  • To skip over certain blocks of code during execution
  • It is not necessary to label errors


πŸ“Œ What are the most common modes used when opening a file?

  • (a)ppend, (r)ead, (w)rite
  • (a)ppend, (c)lose, (w)rite
  • (a)ppend, (r)edline, (w)rite
  • (s)ave, (r)ead, (w)rite


πŸ“Œ What is the data attribute that will return the title of the file?

  • File1.close()
  • File1.mode
  • File1.open()
  • File1.name


πŸ“Œ What is the command that tells Python to begin a new line?

  • \e
  • \b
  • \q
  • \n


πŸ“Œ What attribute is used to input data into a file?

  • File1.write()
  • File1.open()
  • File1.close()
  • File1.read()


πŸ“Œ What python object do you cast to a dataframe?

  • set
  • tuple
  • Dictionary


πŸ“Œ How would you access the first-row and first column in the dataframe df?

  • df.ix[0,0]
  • df.ix[0,1]
  • df.ix[1,0]


πŸ“Œ What is the proper way to load a CSV file using pandas?

  • pandas.from_csv(β€˜data.csv’)
  • pandas.load_csv(β€˜data.csv’)
  • pandas.read_csv(β€˜data.csv’)
  • pandas.import_csv(β€˜data.csv’)


πŸ“Œ What is the Python library used for scientific computing and is a basis for Pandas?

  • Tkinter
  • Requests
  • datetime
  • Numpy


πŸ“Œ What attribute is used to retrieve the number of elements in an array?

  • a.size
  • a.ndim
  • a.shape
  • a.dtype


πŸ“Œ How would you change the first element to β€œ10” in this array c:array([100,1,2,3,0])?

  • c[2]=10
  • c[1]=10
  • c[0]=10
  • c[4]=10


πŸ“Œ What attribute is used to return the number of dimensions in an array?

  • a.ndim

  • a.shape

  • a.dtype

  • a.size


πŸ“Œ What is the result of the following lines of code?

a=np.array([0,1])
b=np.array([1,0])
np.dot(a,b) 
  • 0
  • 1
  • array([1,1])


πŸ“Œ How do you perform matrix multiplication on the numpy arrays A and B ?

  • AB
  • A+B
  • np.dot(A,B)


πŸ“Œ 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
  • array([2,2])
  • array([1,0,1])
  • array([0,1])


πŸ“Œ 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)
  • array([[2,1],[1,2]])
  • array([[2,0],[1,0]])
  • array([[3,1],[1,3] ])


πŸ“Œ 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 1

This is line 2 This is line 3

  • This is line 1
  • This


πŸ“Œ Consider the following line of code:

with open(example1,"r") as file1:

What mode is the file object in?

  • read
  • write
  • append


πŸ“Œ 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")
  • Read the file β€œExample.txt”
  • Write to the file β€œExample.txt”
  • Append the file β€œExample.txt”


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

  • df.iloc[1,0]
  • df.iloc[2,1]
  • df.iloc[0,1]


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

  • x=df[β€˜Length’]
  • x=df[[β€˜Length’]]
  • x=df.[[β€˜Length’]]


πŸ“Œ What does API stand for?

  • Application Programming Interaction
  • Application Programming Interface
  • Automatic Program Interaction
  • Application Process Interface


πŸ“Œ The chart used to plot the cryptocurrency data in the lab is a

  • Candlestick Chart
  • Line Chart
  • Pole Chart
  • Point and Figure Chart


πŸ“Œ What information are we trying to find for each day in the lab for the chart?

  • Open (Last), High (Max), Low (Min), Close (First)
  • Open (Max), High (First), Low (Last), Close (Min)
  • Open (First), High (Max), Low (Min), Close (Last)
  • Open (Min), High (First), Low (Max), Close (Last)


πŸ“Œ What is the function of β€œGET” in HTTP requests?

  • Deletes a specific resource
  • Sends data to create or update a resource
  • Carries the request to the client from the requestor
  • Returns the response from the client to the requestor


πŸ“Œ What does URL stand for?

  • Uniform Request Location
  • Uniform Resource Locator
  • Unilateral Resistance Locator
  • Uniform Resource Learning


πŸ“Œ What does the file extension β€œcsv” stand for?

  • Comma Separated Values
  • Comma Separation Valuations
  • Common Separated Variables
  • Comma Serrated Values


πŸ“Œ What is webscraping?

  • The process to extract data from a particular website
  • The process to display all data within a URL
  • The process to describe communication options
  • The process to request and retrieve information from a client


πŸ“Œ What are the 3 parts to a response message?

  • Start or status line, header, and body
  • Encoding, body, and cache
  • Bookmarks, history, and security
  • HTTP headers, blank line, and body


πŸ“Œ What is the purpose of this line of code "table_row=table.find_all(name=’tr’)" used in webscraping?

  • It will find all of the data within the table marked with a tag β€œp”
  • It will find all of the data within the table marked with a tag β€œa”
  • It will find all of the data within the table marked with a tag β€œh1”
  • It will find all of the data within the table marked with a tag β€œtr”


πŸ“Œ In what data structure do HTTP responses generally return?

  • Tuples
  • Nested Lists
  • JSON
  • Lists


πŸ“Œ The Python library we used to plot the chart in the lab is

  • Pandas
  • MatPlotLib
  • Plotly
  • PyCoinGecko

Final Quiz


πŸ“Œ In Python what statement would print out the first two elements β€œLi” of β€œLizz”?

  • print(name[1:2])
  • print(name[0:2])
  • print(name[2:0])


πŸ“Œ If var = β€œ01234567” what Python statement would print out only the odd elements?

  • print(var[2::2])
  • print(var[1::2])
  • print(var[3::1])


πŸ“Œ Consider the string Name=”EMILY”, what statement would return the index of 0?

  • Name.find(β€œI”)
  • Name.find(β€œL”)
  • Name.find(β€œE”)


πŸ“Œ In Python what can be either a positive or negative number but does not contain a decimal point?

  • str
  • int
  • float


πŸ“Œ What following code segment would return a 3?

  • int(3.99)
  • str(3.99)
  • float(3.99)


πŸ“Œ What following code segment would produce an output of β€œ0”?

  • 1//2
  • 1/2


πŸ“Œ In Python 3, what is the type of the variable x after the following: x=2/2 ?

  • int
  • float


πŸ“Œ Whatdata type must have unique keys?

  • Tuple
  • Dictionary
  • List


πŸ“Œ What will this code segment β€œA[0]” obtain from a list or tuple?

  • The first element of a list or tuple
  • The third element of a list or tuple
  • The second element of a list or tuple


πŸ“Œ What does the split() method return from a list of words?

  • The list of words in a string separated by a delimiter
  • The list of words in reverse order
  • The list of words separated by a colon
  • The list in one long string


πŸ“Œ Tuples are:

  • Not mutable
  • Unordered
  • Not indexed
  • Mutable


πŸ“Œ What is a collection that is unordered, unindexed and does not allow duplicate members?

  • Set
  • List
  • Tuple


πŸ“Œ What value of x will produce the following output? How are you?

x= 
if(x!=1): 
 print('How are you?') 
else: 
 print('Hi')
  • x=β€œ7”
  • x=1
  • x=6


πŸ“Œ Why is the β€œfinally” statement used?

  • Execute the remaining code no matter the end result
  • Only execute the remaining code if one condition is false
  • Only execute the remaining code if no errors occur
  • Only execute the remaining code if an error occurs


πŸ“Œ Given the function add shown below, what does the following return? def add(x): return(x+x) add(β€˜1’)

  • β€˜2’
  • 2
  • β€˜11’


πŸ“Œ What function returns a sorted list?

  • sorted()
  • lower()
  • find()
  • sort()


πŸ“Œ What is the output of the following few lines of code? A=[β€˜1’,β€˜2’,β€˜3’] for a in A: print(2*a)

  • 2
    4
    6
  • error: cannot multiply a string by an integer
  • 11
    22
    33


πŸ“Œ What is the output of the following? for i in range(1,5): if (i!=2): print(i)

  • 1
    3
    4
  • 2
  • 1
    2
    3
    4


πŸ“Œ Consider the class Rectangle, what are the data attributes?

class Rectangle(object):
    def __init__(self,width=2,height =3,color='r'):
        self.height=height
        self.width=width
        self.color=color
        
    def drawRectangle(self):
        import matplotlib.pyplot as plt
        
        plt.gca().add_patch(plt.Rectangle((0, 0), self.width, self.height, fc=self.color))
        plt.axis('scaled')
        plt.show() 
  • self.height, self.width,self.color
  • drawRectangle
  • init


πŸ“Œ What line of code would produce the following: array([0, 0, 0, 0, 0]) ?

  • a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a-b
  • a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a*b
  • a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a+b


πŸ“Œ What is the result of the following lines of code?

a=np.array([1,1,1,1,1]) a+10
  • array([1,1,1,1,1])
  • array([10,10,10,10,10])
  • array([11, 11, 11, 11, 11])


πŸ“Œ The following line of code selects the columns along with what headers from the dataframe df?

y=df[['Artist','Length','Genre']]
  • β€˜Artist’, β€˜Length’ and β€˜Genre’
  • This line of code does not select the headers
  • β€˜Artist’, β€˜Length’ and β€˜y’


πŸ“Œ What is the method readline() used for?

  • It helps to read one complete line from a given text file
  • It reads the entire file all at once
  • It reads 10 lines of a file at a time


πŸ“Œ What mode over writes existing text in a file?

  • Write β€œw”
  • Read β€œr”
  • Append β€œa”


πŸ“Œ What are the 3 parts to a URL?

  • Put, route, and get
  • Scheme, internet address, and route
  • Get, post, and scheme
  • Block, post, and route
Thank You for Visiting My Blog, Have a Good Day πŸ˜†
Β© 2021 Bae Kim, Powered By Gatsby.