Python for Data Science, AI & Development
Final Exam Quiz Answers
Final Exam
Question 1)
When slicing in Python what does the “0” in this statement [0:2] specify ?
- It specifies the position to start the slice
Question 2)
If var = “01234567” what Python statement would print out only the odd elements ?
- print(var[1::2])
Question 3)
Consider the string Name=”EMILY”, what statement would return the index of 0 ?
- Name.find("E")
Question 4)
What is the type of the following: 1.0
- float
Question 5)
What is the result of the following code segment: int(3.99)
- 3
Question 6)
What is the result of the following code segment:1/2 ?
- 0.5
Question 7)
In Python 3, what is the type of the variable x after the following: x=2/2 ?
- float
Question 8)
Dictionary items can be:
- Numerous data types
Question 9)
What is a tuple ?
- A collection that is ordered and unchangeable
Question 10)
What is the result of the following operation: '1:2,3:4'.split(':') ?
- ['1', '2,3', '4']
Question 11)
What is an important difference between lists and tuples ?
- Lists are mutable tuples are not
Question 12)
How do you cast the list A to the set a ?
- a=set(A)
Question 13)
If x=1 what will produce the below output ?
Hi
Mike
if(x!=1):
print('Hello')
else:
print('Hi')
print('Mike')
Question 14)
What statement will execute the remaining code no matter the end result ?
- Finally
Question 15)
What add function would return ‘4’ ?
- def add(x): return(x+x) add(2)
Question 16)
What method organizes the elements in a given list in a specific descending or ascending order ?
- 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
- 7
- 10
Question 18)
What is the output of the following ?
for i in range(1,5): if (i!=2): print(i)
- 1
- 3
- 4
Question 19)
What is the height of the rectangle in the class Rectangle ?
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()
- 3
Question 20)
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
- Division by zero error
Question 21)
What is the result of the following lines of code ?
a=np.array([1,1,1,1,1]) a+10
- array([11, 11, 11, 11, 11])
Question 22)
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’
Question 23)
What is the method readline() used for?
- It helps to read one complete line from a given text file
Question 24)
Consider the following 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)
- It specifies the position to end the slice
- 1
- float
- int(3.99)
- Rounded
- Float
- Dictionary
- A[0]
- The list of words in a string separated by a delimiter
- Lists are mutable tuples are not
- b=set(B)
- for i in range(1,5): if (i!=1): print(i)
- array([0, 0, 0, 0, 0])
What is the result of the following lines of code ?
a=np.array([10,9,8,7,6]) a+1
- array([11,10,9,8,7])
Question 40)
How would you select the columns with the headers: Artist, 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(4)
- 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("Example.txt","a") as file1:
- print(name[0:2])
- 0246
- Name.find("E")
- int
- 1/2
- Float
- The second element
- '11'
- sorted()
- A=['1','2','3'] for a in A: print(2*a)
- a=np.array([1,1,1,1,1]) a+10
- str
- Dictionary
- Mutable
- Exception handling
- strings and numeric values
- drawRectangle
- array([1, 1, 1, 1, 1])
- Write “w”
- print(var[::2])
- 1/2
- The first element of a list or tuple
- '1,2,3,4'.split(',')
- Exception
- def add(x): return(x+x) add(1)
- 11
- 22
- 33
- for i in range(1,5): if (i==2): print(i)
- 2
- array([1, 1, 1, 1, 1])
2 Comments
nice share more new updated questions..
ReplyDeleteHelped a lot, thank you!
ReplyDelete