Python for Data Science, AI & Development Final Exam Quiz Answers

Python for Data Scientific discipline, AI & Development

Final Exam Quiz Answers

Final Test

Question 1)

When slicing in Python what does the "0" in this statement [0:2] specify ?

  • It specifies the position to first the slice

Question 2)

If var = "01234567" what Python statement would impress out only the odd elements ?

  • print(var[1::2])

Question 3)

Consider the string Name="EMILY", what statement would return the alphabetize of 0 ?

  • Name.observe("E")

Question iv)

What is the type of the post-obit: 1.0

  • float

Question 5)

What is the upshot of the following code segment: int(three.99)

  • three

Question vi)

What is the result of the following lawmaking segment:1/ii ?

  • 0.5

Question 7)

In Python three, what is the type of the variable ten afterwards the following: x=2/2 ?

  • bladder

Question eight)

Dictionary items tin exist:

  • Numerous data types

Question nine)

What is a tuple ?

  • A collection that is ordered and unchangeable

Question x)

What is the result of the post-obit performance: '1:2,3:iv'.separate(':') ?

  • ['1', '2,3', '4']

Question eleven)

What is an important difference between lists and tuples ?

  • Lists are mutable tuples are not

Question 12)

How practise you bandage the list A to the set a ?

  • a=set(A)

Question 13)

If x=1 what will produce the beneath output ?

Hi

Mike

if(ten!=1):

print('Howdy')

 else:

    print('How-do-you-do')

 print('Mike')

Question 14)

What argument will execute the remaining code no matter the end result ?

  • Finally

Question 15)

What add together function would return '4' ?

  • def add(10): return(x+x) add(2)

Question 16)

What method organizes the elements in a given list in a specific descending or ascending social club ?

  • sort()

Question 17)

What is the output for the beneath line of code ?

A=[8,5,2] for a in A: impress(12-a)

  •  4
  •  7
  •  10

Question 18)

What is the output of the following ?

 for i in range(1,5): if (i!=2): print(i)

  • 1
  • 3
  • iv

Question 19)

What is the height of the rectangle in the class Rectangle ?

class Rectangle(object): def __init__(self,width=2,superlative =three,color='r'): self.height=tiptop self.width=width self.color=color def drawRectangle(self): import matplotlib.pyplot as plt plt.gca().add_patch(plt.Rectangle((0, 0),self.width, cocky.tiptop ,fc=self.color)) plt.centrality('scaled') plt.show()

  • three

Question 20)

What is the result of the following lines of code ?

 a=np.array([0,i,0,ane,0]) b=np.assortment([i,0,1,0,1]) a/b

  • Division by zero mistake

Question 21)

What is the issue of the following lines of lawmaking ?

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

  • assortment([11, 11, eleven, 11, 11])

Question 22)

The post-obit line of code selects the columns forth with what headers from the dataframe df ?

y=df[['Creative person','Length','Genre']]

  • 'Artist', 'Length' and 'Genre'

Question 23)

What is the method readline() used for?

  • It helps to read one consummate line from a given text file

Question 24)

Consider the following line of code:

 with open("Example.txt","a") every bit file1:

What style is the file object in?

  • suspend

Question 25)

What does URL stand for ?

  • Uniform Resources Locator

Question 26)

When slicing in Python what does the "2" in this statement [0:2] specify ?

  • It specifies the position to end the slice

Question 27)

Consider the string Name="ABCDE", what is the result of the following operation Name.find("B") ?

  • 1

Question 28)

What is the type of the following: 1.0

  • float

Question 29)

What following code segment would render a 3 ?

  • int(three.99)

Question 30)

When using the double slash "//" for integer sectionalisation the consequence will exist ?

  • Rounded

Question 31)

In Python iii what does regular division always consequence in ?

  • Float

Question 32)

Whatdata type must have unique keys ?

  • Dictionary

Question 33)

What is the syntax to obtain the first element of the tuple ?

A=('a','b','c')

  • A[0]

Question 34)

What does the split up() method return from a listing of words ?

  • The list of words in a string separated past a delimiter

Question 35)

What is an important difference betwixt lists and tuples ?

  • Lists are mutable tuples are not

Question 36)

What lawmaking segment is used to bandage listing "B" to the set "b" ?

  • b=set(B)

Question 37)

What code segment would output the following ?

  • for i in range(1,5): if (i!=1): print(i)

Question 38)

What is the consequence of the following lines of code ?

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

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

Question 39)

What is the issue of the following lines of code ?

a=np.array([10,9,eight,seven,6]) a+ane

  • array([xi,10,9,viii,7])

Question 40)

How would yous select the columns with the headers: Creative person, Length and Genre from the dataframe df and assign them to the variable y ?

  • y=df[['Creative person','Length','Genre']]

Question 41)

Consider the file object: File1.What would the following line of code output?

file1.readline(4)

  • It would output the first four characters from the text file

Question 42)

Which line of code is in the mode of append ?

  • with open up("Example.txt","a") as file1:

Question 43)

In Python what argument would impress out the first 2 elements "Li" of "Lizz" ?

  • print(name[0:2])

Question 44)

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

  • 0246

Question 45)

Consider the string Name="EMILY", what statement would return the index of 0 ?

  • Name.notice("Due east")

Question 46)

In Python what can exist either a positive or negative number but does not incorporate a decimal point ?

  • int

Question 47)

What following code segment would produce an output of "0.5" ?

  • 1/2

Question 48)

In Python three what does regular division e'er upshot in ?

  • Float

Question 49)

What does the index of "one" correspond to in a list or tuple ?

  • The second element

Question 50)

Given the function add shown below, what does the following return ?

 def add(x): return(x+x) add('i')

  • 'eleven'

Question 51)

What function returns a sorted list ?

  • sorted()

Question 52)

What segment of code would output the following ?

11

22

33

  • A=['1','2','3'] for a in A: print(2*a)

Question 53)

What line of code would produce the following: assortment([11, 11, 11, 11, 11]) ?

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

Question 54)

In Python what information blazon is used to correspond text and non numbers ?

  • str

Question 55)

Whatdata type must accept unique keys ?

  • Dictionary

Question 56)

Lists are:

  • Mutable

Question 57)

What is the process of forcing your program to output an error message when it encounters an effect ?

  • Exception handling

Question 58)

A listing cannot exist sorted if it contains:

  • strings and numeric values

Question 59)

What is the method defined in the class Rectangle used to draw the rectangle?

course Rectangle(object): def __init__(self,width=two,meridian =three,color='r'): self.superlative=summit self.width=width self.color=colour def drawRectangle(self): import matplotlib.pyplot as plt plt.gca().add_patch(plt.Rectangle((0, 0),self.width, self.peak ,fc=cocky.color)) plt.axis('scaled') plt.show()

  • drawRectangle

Question sixty)

What is the result of the following lines of code ?

 a=np.assortment([0,one,0,ane,0]) b=np.assortment([1,0,ane,0,1]) a+b

  • assortment([1, 1, ane, 1, 1])

Question 61)

What mode over writes existing text in a file ?

  • Write "west"

Question 62)

If var = "01234567" what Python argument would print out only the even elements?

  • print(var[::ii])

Question 63)

In Python 3 what following code segment will produce a float ?

  • 1/two

Question 64)

What will this lawmaking segment "A[0]" obtain from a listing or tuple ?

  • The kickoff element of a list or tuple

Question 65)

What line of code would produce this output: ['1','2','three','4'] ?

  • '1,2,3,4'.split up(',')

Question 66)

What is an error that occurs during the execution of code ?

  • Exception

Question 67)

What add function would return '2' ?

  • def add(x): render(x+x) add together(1)

Question 68)

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

 A=['ane','two','3'] for a in A: print(ii*a)

  • 11
  • 22
  • 33

Question 69)

What code segment would output the following ?

2

  • for i in range(one,5): if (i==2): print(i)

Question 70)

What is the width of the rectangle in the class Rectangle?

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

  • 2

Question 71)

What is the result of the following lines of code ?

 a=np.array([0,1,0,1,0]) b=np.assortment([1,0,i,0,one]) a+b

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