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

Python for Data Science, AI & Development

Terminal Examination Quiz Answers

Final Examination

Question 1)

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

  • It specifies the position to starting time the piece

Question 2)

If var = "01234567" what Python statement would print out simply the odd elements ?

  • print(var[1::ii])

Question three)

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

  • Proper name.find("E")

Question iv)

What is the type of the post-obit: one.0

  • float

Question 5)

What is the result of the post-obit code segment: int(three.99)

  • 3

Question 6)

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

  • 0.5

Question 7)

In Python 3, what is the type of the variable x afterward the following: ten=two/2 ?

  • float

Question 8)

Dictionary items can be:

  • Numerous data types

Question 9)

What is a tuple ?

  • A drove that is ordered and unchangeable

Question 10)

What is the result of the post-obit operation: 'ane:ii,3:4'.split up(':') ?

  • ['one', '2,iii', '4']

Question 11)

What is an important difference betwixt lists and tuples ?

  • Lists are mutable tuples are not

Question 12)

How do you cast the listing A to the prepare a ?

  • a=set(A)

Question 13)

If x=i what will produce the beneath output ?

How-do-you-do

Mike

if(x!=1):

print('Hello')

 else:

    print('Hullo')

 print('Mike')

Question fourteen)

What statement will execute the remaining code no affair the cease result ?

  • Finally

Question 15)

What add function would render '4' ?

  • def add together(x): return(x+ten) add together(2)

Question 16)

What method organizes the elements in a given listing in a specific descending or ascending lodge ?

  • sort()

Question 17)

What is the output for the below line of code ?

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

  •  4
  •  seven
  •  x

Question xviii)

What is the output of the following ?

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

  • 1
  • three
  • iv

Question 19)

What is the pinnacle of the rectangle in the course Rectangle ?

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

  • 3

Question 20)

What is the consequence of the following lines of code ?

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

  • Division past cipher fault

Question 21)

What is the result of the following lines of lawmaking ?

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

  • array([11, 11, 11, 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?

  • Information technology helps to read 1 complete line from a given text file

Question 24)

Consider the post-obit line of code:

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

What mode is the file object in?

  • append

Question 25)

What does URL stand for ?

  • Uniform Resource Locator

Question 26)

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

  • It specifies the position to end the slice

Question 27)

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

  • ane

Question 28)

What is the type of the following: i.0

  • float

Question 29)

What following code segment would render a 3 ?

  • int(3.99)

Question 30)

When using the double slash "//" for integer partition the result will be ?

  • Rounded

Question 31)

In Python 3 what does regular division always effect in ?

  • Float

Question 32)

Whatdata blazon must take 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 dissever() method return from a list of words ?

  • The list of words in a cord separated by a delimiter

Question 35)

What is an important deviation betwixt lists and tuples ?

  • Lists are mutable tuples are not

Question 36)

What code segment is used to cast list "B" to the prepare "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 issue of the following lines of lawmaking ?

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

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

Question 39)

What is the result of the following lines of code ?

a=np.array([10,9,8,7,6]) a+1

  • array([11,ten,9,8,7])

Question 40)

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

  • y=df[['Artist','Length','Genre']]

Question 41)

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

file1.readline(four)

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

Question 42)

Which line of code is in the mode of append ?

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

Question 43)

In Python what statement would print out the first two elements "Li" of "Lizz" ?

  • print(name[0:2])

Question 44)

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

  • 0246

Question 45)

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

  • Name.notice("E")

Question 46)

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

  • int

Question 47)

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

  • i/2

Question 48)

In Python 3 what does regular partitioning always result in ?

  • Float

Question 49)

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

  • The second chemical element

Question l)

Given the part add shown below, what does the post-obit return ?

 def add(x): return(x+ten) add('1')

  • 'eleven'

Question 51)

What function returns a sorted list ?

  • sorted()

Question 52)

What segment of code would output the following ?

xi

22

33

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

Question 53)

What line of lawmaking would produce the post-obit: array([11, eleven, 11, 11, 11]) ?

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

Question 54)

In Python what information type is used to represent text and non numbers ?

  • str

Question 55)

Whatdata blazon must have unique keys ?

  • Lexicon

Question 56)

Lists are:

  • Mutable

Question 57)

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

  • Exception treatment

Question 58)

A list cannot be sorted if information technology contains:

  • strings and numeric values

Question 59)

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

class Rectangle(object): def __init__(self,width=2,height =three,colour='r'): cocky.elevation=acme 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.top ,fc=self.color)) plt.axis('scaled') plt.evidence()

  • drawRectangle

Question 60)

What is the result of the following lines of code ?

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

  • array([1, 1, ane, ane, one])

Question 61)

What mode over writes existing text in a file ?

  • Write "due west"

Question 62)

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

  • impress(var[::2])

Question 63)

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

  • 1/2

Question 64)

What volition this code segment "A[0]" obtain from a list or tuple ?

  • The start element of a listing or tuple

Question 65)

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

  • '1,2,iii,4'.split(',')

Question 66)

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

  • Exception

Question 67)

What add together function would return '2' ?

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

Question 68)

What is the output of the post-obit few lines of code ?

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

  • 11
  • 22
  • 33

Question 69)

What lawmaking segment would output the following ?

2

  • for i in range(1,5): if (i==2): impress(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'): 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),cocky.width, cocky.top ,fc=self.color)) plt.axis('scaled') plt.evidence()

  • two

Question 71)

What is the consequence of the following lines of lawmaking ?

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

  • array([one, ane, 1, 1, ane])