Tuesday , December 24 2024
Breaking News

Python for Data Science Cognitive Class Exam Quiz Answers

Python For Data Science Cognitive Class Certification Answers

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

3 + 2 * 2

  • 10
  • 7
  • 9
  • 12

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

  • Lizz
  • L
  • Liz
  • Li

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

  • 0246
  • 1357
  • 1234567
  • 8903

Question 4: In Python, what is the result of the following operation ‘1’+’2′?

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

Question 5: Given myvar = ‘hello’, how would you convert myvar into uppercase?

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

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

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

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

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

  • True
  • False

Question 3: 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 4: 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 5: 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.

Question 1: 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 2: 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 3: 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 4: 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 5: What are the keys of the following dictionary: {‘a’:1,’b’:2}?

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

Question 1: 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 2: 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 3: 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 4: 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.

Question 1: 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 2: 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 3: 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 4: What is the correct code to perform matrix multiplication on the matrix A and B?

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

1) What is the result of the following operation 3+2*2?

  • 3
  • 12
  • 9
  • 7

2) What is the type of the following variable: True?

  • int
  • bool
  • str
  • list

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

  • 3.2
  • 3
  • 4
  • ‘3.2’

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

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

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

  • 5
  • 4
  • 5,6
  • -1

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

you cant add two strings

  • 3
  • ‘3’
  • ’12’

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

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

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

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

9)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]

10) 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

11) 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’

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

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

13) How do you cast the list ‘A’ to the set ‘a’?

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

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

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

15) 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

16) 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

17) 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

18) how many iterations are performed in the following loop?

for n in range(3):

            print(n)

  • 1
  • 2
  • 3
  • 4

19) 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

20) 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

21) 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’

22) 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

23) 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

24) 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

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

What mode is the file object in?

  • read
  • write
  • append

Introduction to Python for Data Science

Python is a versatile and powerful programming language widely used in data science due to its simplicity, readability, and extensive ecosystem of libraries. Here’s an introductory overview of Python for data science:

  1. Installation: Before you start coding, you need to install Python on your system. You can download it from the official Python website (python.org) or use distributions like Anaconda, which come bundled with popular data science libraries.
  2. Python Basics:
    • Variables: You can assign values to variables using the “=” sign. Python supports various data types such as integers, floats, strings, lists, tuples, dictionaries, etc.
    • Control Structures: Python supports if-else statements, loops (for and while), and other control structures to control the flow of execution.
    • Functions: You can define functions using the def keyword to encapsulate reusable pieces of code.
    • Modules and Packages: Python allows you to organize code into modules and packages for better manageability and reusability.
  3. Python Libraries for Data Science:
    • NumPy: NumPy is the fundamental package for scientific computing with Python. It provides support for arrays, matrices, and mathematical functions.
    • Pandas: Pandas is a library for data manipulation and analysis. It provides powerful data structures like DataFrames for working with structured data.
    • Matplotlib and Seaborn: These libraries are used for data visualization. Matplotlib offers basic plotting functionalities, while Seaborn provides a high-level interface for attractive statistical graphics.
    • Scikit-learn: Scikit-learn is a machine learning library that provides simple and efficient tools for data mining and data analysis.
    • TensorFlow and PyTorch: These are deep learning frameworks widely used for building and training neural networks.
  4. Jupyter Notebooks: Jupyter Notebooks are interactive documents that allow you to combine code, visualizations, and explanatory text in a single document. They are widely used in data science for exploratory data analysis, prototyping, and sharing results.
  5. Data Visualization: Visualizing data is essential for gaining insights and communicating results. Matplotlib, Seaborn, and other libraries provide various plotting functions to create informative visualizations.
  6. Data Analysis and Manipulation: Pandas offers powerful tools for data cleaning, transformation, and analysis. You can filter, aggregate, merge, and reshape data easily using Pandas DataFrames.
  7. Machine Learning: Python’s extensive ecosystem of libraries makes it a popular choice for machine learning tasks. Scikit-learn provides implementations of various machine learning algorithms for classification, regression, clustering, and more.
  8. Deep Learning: TensorFlow and PyTorch are widely used for deep learning tasks such as image recognition, natural language processing, and reinforcement learning. These libraries offer high-level APIs for building and training neural networks.
  9. Data Access: Python provides various libraries for accessing and manipulating different types of data, including CSV files, Excel spreadsheets, databases (e.g., SQLite, PostgreSQL), JSON, XML, and web APIs.
  10. Community and Resources: Python has a large and active community of developers and data scientists. There are plenty of online resources, tutorials, and forums where you can seek help, share knowledge, and collaborate with others.

In summary, Python is an excellent choice for data science due to its simplicity, versatility, and rich ecosystem of libraries and tools. Whether you’re a beginner or an experienced programmer, Python offers everything you need to explore, analyze, and visualize data effectively.

About Clear My Certification

Check Also

Controlling Hadoop Jobs using Oozie Cognitive Class Exam Quiz Answers

Enroll Here: Controlling Hadoop Jobs using Oozie Cognitive Class Exam Quiz Answers Controlling Hadoop Jobs …

Leave a Reply

Your email address will not be published. Required fields are marked *