Python for Data Science Quiz Answer – Cognitive Class

Get Python for Data Science Quiz Answer

This introduction to Python will kickstart your learning of Python for data science, as well as programming in general. This beginner-friendly Python course will take you from zero to programming in Python in a matter of hours.

Upon its completion, you’ll be able to write your own Python scripts and perform basic hands-on data analysis using our Jupyter-based lab environment. If you want to learn Python from scratch, this free course is for you.

You can start creating your own data science projects and collaborating with other data scientists using IBM Watson Studio. When you sign up, you get free access to Watson Studio. Start now and take advantage of this platform.

Enroll on Cognitive Class

Module 1 – Python Basics

Question: What is the result of the following operation in Python:

3 + 2 * 2

  • 10
  • 7
  • 9
  • 12

Question: In Python, if you executed name = 'Lizz', what would be the output of print(name[0:2])?

  • Lizz
  • L
  • Liz
  • Li

Question: In Python, if you executed var = '01234567', what would be the result of print(var[::2])?

  • 0246
  • 1357
  • 1234567
  • 8903

Question: In Python, what is the result of the following operation '1'+'2'?

  • ‘2’
  • ‘3’
  • ’12’
  • 3

Question: Given myvar = 'hello', how would you convert myvar into uppercase?

  • len(myvar)
  • myvar.find(‘hello’)
  • myvar.upper()
  • myvar.sum()

Module 2 – Python Data Structures

Question: What is the syntax used to obtain the first element of the tuple:

A = (‘a’,’b’,’c’)

  • A[1]
  • A[0]
  • A[:]

Question: After applying the following method, L.append([‘a’,’b’]), the following list will only be one element longer.

  • True
  • False

Question: How many duplicate elements can you have in a set?

  • 1
  • 0. You can only have one unique element in a set.
  • 100
  • Depends on the number of elements in your set.

Question: 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
  • 3
  • [3,3,3]
  • (4,4,4)
  • Error

Question: What is an important difference between lists and tuples?

  • Lists can’t contain a string.
  • Tuples can only have integers.
  • Lists and tuples are the same.
  • Lists are mutable, tuples are not.
  • There are no zeros in lists.

Module 3 – Python Programming Fundamentals

Question: What is the output of the following lines of code:

x=1

if(x!=1):

print(‘Hello’)

else:

print(‘Hi’)

print(‘Mike’)

  • Hi Mike
  • Mike
  • Hello Mike
  • The Mike

Question: What is the output of the following few lines of code?

A = [‘1′,’2′,’3’]

for a in A:

print(2*a)

  • 246
  • ‘2’ ‘4’ ‘6’
  • ’11’ ’22’ ’33’
  • A B C

Question: 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.

Question: What is the correct way to sort the list ‘B’ using a method? The result should not return a new list, just change the list ‘B’.

  • B.sort()
  • sort(B)
  • sorted(B)
  • B.sorted()

Question: What are the keys of the following dictionary: {'a':1,'b':2}?

  • 1,2
  • ;,:
  • a,b

Module 4 – Working with Data in Python

Question: What do the following lines of code do?

with open(“Example1.txt”,”r”) as file1:

FileContent=file1.readlines()

print(FileContent)

  • Read the file “Example1.txt”.
  • Write to the file “Example1.txt”.
  • Append the file “Example1.txt”.

Question: What do the following lines of code do?

with open(“Example2.txt”,”w”) as writefile:

writefile.write(“This is line A\n”)

writefile.write(“This is line B\n”)

  • Read the file “Example2.txt”.
  • Write to the file “Example2.txt”.
  • Append the file “Example2.txt”.

Question: What do the following lines of code do?

with open(“Example3.txt”,”a”) as file1:

file1.write(“This is line C\n”)

  • Read the file “Example3.txt”.
  • Write to the file “Example3.txt”.
  • Append the file “Example3.txt”.

Question: What is the result of applying the following method df.head() to the dataframe “df”?

  • Prints the first row of the dataframe.
  • Prints the first column of the dataframe.
  • Prints the first 5 rows of the dataframe.
  • Prints out the entire dataframe.

Module 5 – Working with Numpy Arrays & Simple APIS

Question: What is the result of the following lines of code:

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

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

a*b

  • 0
  • array([1, 1, 1, 1, 1])
  • array([0, 0, 0, 0, 0])

Question: What is the result of the following lines of code:

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

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

np.dot(a,b)

  • 1
  • array([1,1])
  • 0
  • array([0,0])

Question: What is the result of the following lines of code:

a=np.array([1,1,1,1,1])

a+10

  • array([10,10,10,10,10])
  • array([11,11,11,11,11])
  • array([1,1,1,1,1])

Question: What is the correct code to perform matrix multiplication on the matrix A and B?

  • np.dot(A,B)
  • A*B
  • AxB

Final Exam

Question: What is the result of the following operation 3+2*2?

  • 3
  • 12
  • 9
  • 7

Question: What is the type of the following variable: True?

  • int
  • bool
  • str
  • list

Question: What is the result of the following operation int(3.2)?

  • 3.2
  • 3
  • 4
  • ‘3.2’

Question: Consider the string A=’1234567′, what is the result of the following operation: A[1::2]

  • ‘1234567’
  • ‘246’
  • ‘1357’
  • error

Question: Consider the string Name=”Michael Jackson” , what is the result of the following operation Name.find(‘el’)

  • 5
  • 4
  • 5,6
  • -1

Question: The variables A=’1′ and B=’2′ ,what is the result of the operation A+B?

  • you cant add two strings
  • 3
  • ‘3’
  • ’12’

Question: Consider the variable F=”You are wrong”, Convert the values in the variable F to uppercase?

  • F.up()
  • F.upper
  • F.upper()

Question: Consider the tuple tuple1=(“A”,”B”,”C” ), what is the result of the following operation tuple1[-1]?

  • “A”
  • “B”
  • “C”

Question: 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)
  • [21,22]

Question: Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation A[0][1]:

  • 12
  • 11
  • 22
  • 21

Question: What is the result of the following operation ‘1,2,3,4’.split(‘,’)

  • ‘1’,’2′,’3′,’4′
  • (‘1′,’2′,’3′,’4’)
  • [‘1′,’2′,’3′,’4’]
  • ‘1234’

Question: Concatenate the following lists A=[1,’a’] and B=[2,1,’d’]:

  • A+B
  • A-B
  • A*B
  • A/B

Question: How do you cast the list ‘A’ to the set ‘a’?

  • a.set()
  • a=A.append()
  • a=A.dict()
  • a=set(A)

Question: Consider the Set: V={‘A’,’B’}, what is the result of V.add(‘C’)?

  • {‘A’,’B’}
  • {‘A’,’B’,’C’}
  • {‘AC’,’BC’}
  • error

Question: Consider the Set: V={‘A’,’B’,’C’ }, what is the result of V.add(‘C’)?

  • {‘A’,’B’}
  • {‘A’,’B’,’C’}
  • {‘A’,’B’,’C’,’C’}
  • error

Question: What is the output of the following lines of code:

x=”Go”

if(x!=”Go”):

print(‘Stop’)

else:

print(‘Go ‘)

print(‘Mike’)

  • Go Mike
  • Mike
  • Stop Mike
  • The Mike

Question: What is the output of the following lines of code:

x=”Go”

if(x==”Go”):

print(‘Go ‘)

else:

print(‘Stop’)

print(‘Mike’)

  • Go Mike
  • Mike
  • Stop Mike
  • The Mike

Question: how many iterations are performed in the following loop?

for n in range(3):

print(n)

  • 1
  • 2
  • 3
  • 4

Question: What does the following loop print?

for n in range(3):

print(n+1)

  • 0 1 2
  • 1 2 3
  • 3 2 1
  • 2 1 0

Question: 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
  • ‘2’ ‘4’ ‘6’
  • ’11’ ’22’ ’33’
  • A B C

Question: Consider the function add, what is the result of calling the following Add(‘1′,’1’) (look closely at the return statement )

def Add(x,y):

z=y+x

return(y)

  • error
  • ‘2’
  • ’11’
  • ‘1’

Question: Consider the class Points, what are the data attributes:

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)

  • __init__
  • self.x self.y
  • print_point

Question: 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
  • y=2
  • x=1 y=2

Question: 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=1
  • y=2
  • x=1 y=2
  • x=2 y=2

Question: Consider the following line of code: with open(example1,”r”) as file1:

What mode is the file object in?

  • read
  • write
  • append
Conclusion:

We hope you know the correct answers to Python for Data Science If Queslers helped you to find out the correct answers then make sure to bookmark our site for more Course Quiz Answers.

If the options are not the same then make sure to let us know by leaving it in the comments below.

Course Review:

In our experience, we suggest you enroll in this and gain some new skills from Professionals completely free and we assure you will be worth it.

This course is available on Cognitive Class for free, if you are stuck anywhere between quiz or graded assessment quiz, just visit Queslers to get all Quiz Answers and Coding Solutions.

More Courses Quiz Answers >>

Building Cloud Native and Multicloud Applications Quiz Answers

Accelerating Deep Learning with GPUs Quiz Answers

Blockchain Essentials Cognitive Class Quiz Answers

Leave a Reply

Your email address will not be published.