Quiz
π What is the result of the following operation:
11//2
- 5.5
- 5
π What is the value of x after the following is run:
x=4
x=x/2
- 4.0
- 2.0
π What is the output of the following:
print("AB\nC\nDE")
- ABC
DE -
AB
CD
E - AB
C
DE
π What is the result of following?
If you are unsure, copy and paste the code into Jupyter Notebook and check.
"hello Mike".find("Mike")
- 6
- 6, 7, 8
- 5
π What is the value of x after the following lines of code?
x=2
x=x+2
- 4
- 2
π What is the result of the following operation:
3+2*2
- 3
- 7
- 9
π What is the result of the following code segment:
type(int(12.3))
- int
- str
- float
π What is the result of the following code segment:
int(False)
- 1
- 0
- error
π In Python, what is the result of the following operation:
'1'+'2'
- 3
- β3β
- β12β
π Given myvar = 'hello'
, how would you return myvar as uppercase?
- len(myvar)
- myvar.find(βhelloβ)
- myvar.upper()
π What is the result of the following:
str(1)+str(1)
- β11β
- 2
π What is the result of the following:
"ABC".replace("AB", "ab")
- βabCβ
- βABcβ
π In Python 3, what is the type of the variable x after the following:
x=2/2
- float
- int
π Consider the following tuple:
say_what=('say',' what', 'you', 'will')
what is the result of the following say_what[-1]
- βwillβ
- βsayβ
- β whatβ
- βyouβ
π Consider the following tuple A=(1,2,3,4,5)
. What is the result of the following:
A[1:4]
- (3, 4,5)
- (2, 3, 4,5)
- (2, 3, 4)
π Consider the following tuple A=(1,2,3,4,5)
, what is the result of the following:
len(A)
- 6
- 5
- 4
π Consider the following list B=[1,2,[3,'a'],[4,'b']]
, what is the result of the following:
B[3][1]
- βcβ
- [4,βbβ]
- βbβ
π What is the result of the following operation?
[1,2,3]+[1,1,1]
- TypeError
- [1, 2, 3, 1, 1, 1]
- [2,3,4]
π What is the length of the list A = [1]
after the following operation:
A.append([2,3,4,5])
- 2
- 6
- 5
π What is the result of the following:
"Hello Mike".split()
- [βHβ]
- [βHelloMikeβ]
- [βHelloβ,βMikeβ]
π What are the keys of the following dictionary:
{"a":1,"b":2}
- 1,2
- βaβ,βbβ
π 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, 4, 4)
- [3,3,3]
- 1
π Consider the following set: {"A","A"}
, what will the result be when the set is created?
- {βAβ}
- {βAβ,βAβ}
π What is the result of the following:
type(set([1,2,3]))
- set
- list
π What method do you use to add an element to a set?
- append
- add
- Extend
π What is the result of the following operation:
{'a', 'b'} &{'a'}
- {βaβ, βbβ}
- {βaβ}
π 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]
π Consider the tuple A=((1),[2,3],[4])
, that contains a tuple and list. What is the result of the following operation
A[2][0]
- 4
- [4]
- 1
π True or false: after applying the following method, L.append(['a','b'])
, the following list will only be one element longer.
- True
- False
π Consider the following list A=["hard rock", 10, 1.2]
What will list A contain affter the following command is run:
del(A[1])
- [10,1.2]
- [βhard rockβ,1.2]
- [βhard rockβ,10]
π What is the syntax to clone the list A and assign the result to list B ?
- B=A
- B=A[:]
π Consider the following dictionary:
{ "The Bodyguard":"1992", "Saturday Night Fever":"1977"}
select the values:
- β1977β
- β1992β
- βThe Bodyguardβ
- βSaturday Night Feverβ
π The variable release_year_dict is a Python Dictionary, what is the result of applying the following method:
release_year_dict.values()
- retrieve the keys of the dictionary
- retrieves, the values of the dictionary
π Consider the Set: V={'A','B'}
, what is the result of V.add('C')
?
- {βAβ,βBβ,βCβ}
- {βAβ,βBβ}
- error
π What is the result of the following:
'1' in {'1','2'}
- False
- True
π what is the result of the following:
1=2
- SyntaxError:canβt assign to literal
- False
- True
π What is the output of the following code segment:
i=6
i<5
-
True
-
False
-
SyntaxError: canβt assign to literal
π What is the result of the following:
5!=5
- False
- True
π What is the output of the following code segment:
'a'=='A'
- False
- True
π in the video, if age=18
what would be the result
- move on
- you can enter
π in the video what would be the result if we set the variable age as follows:
age= -10
- go see Meat Loaf
move on - you can enter
move on
π what is the result of the following: True or False
- True, an or statement is only False if all the Boolean values are False
- False
π what will be the output of the following:
for x in range(0,3):
print(x)
- 0
1
2 - 0
1
2
3
π what is the output of the following:
for x in ['A','B','C']:
print(x+'A')
- AA
BA
CA - A
B
C
π what is the output of the following:
for i, x in enumerate(['A','B','C']):
print(i, x)
- 0 A
1 B
2 C - AA
BB
CC
π What does the following function return:
len(['A','B',1])
- 3
- 2
- 4
π What does the following function return:
len([sum([0,0,1])])
- 1
- 0
- 3
π What is the value of list L after the following code segment is run :
L=[1,3,2]
sorted(L)
- L:[1,3,2]
- L:[1,2,3]
- L:[0,0,0]
π From the video what is the value of c after the following:
c=add1(2)
c=add1(10)
-
3
-
11
-
14
π what is the output of the following lines of code:
def Print(A):
for a in A:
print(a+'1')
Print(['a','b','c'])
- a
b
c - a1
b1
C1 - a1
π Why do we use exception handlers?
- Catch errors within a program
- Read a file
- Write a file
- Terminate a program
π What is the purpose of a tryβ¦except statement?
- Executes the code block only if a certain condition exists
- Crash a program when errors occur
- Catch and handle exceptions when an error occurs
- Only executes if one condition is true
π What is the type of the following?
["a"]
-
str
-
list
π What does a method do to an object?
- Changes or interacts with the object
- Returns a new values
π We create the object:
Circle(3,'blue')
What is the color attribute set to?
- 2
- βblueβ
π What is the radius attribute after the following code block is run?
RedCircle=Circle(10,'red')
RedCircle.radius=1
- 10
- 1
- βredβ
π What is the radius attribute after the following code block is run?
BlueCircle=Circle(10,'blue')
BlueCircle.add_radius(20)
- 10
- 20
- 30
π What is the output of the following code?
x="Go"
if(x=="Go"):
print('Go ')
else:
print('Stop')
print('Mike')
- Go Mike
- Mike
- Stop Mike
π What is the result of the following lines of code?
x=1
x>-5
- True
- False
π What is the output of the following few lines of code?
x=5
while(x!=2):
print(x)
x=x-1
- 5
4
3 - 5
4
3
2 - the program will never leave the loop
π 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;
-
x=1 y=2
-
y=2
π What is the output of the following few lines of code?
for i,x in enumerate(['A','B','C']):
print(i+1,x)
- 1 A
2 B
3 C - 0 A
1 B
2 C - 0 AA
1 BB
2 CC
π 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=2 y=2
- x=1 y=2
- x=1 y=1
π 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
π What is the output of the following lines of code?
a=1
def do(x):
a=100
return(x+a)
print(do(1))
- 2
- 101
- 102
π Write a function name add that takes two parameter a and b, then return the output of a + b (Do not use any other variable! You do not need to run it. Only write the code about how you define it.)
def add(a, b):
return a + b
π Why is it best practice to have multiple except statements with each type of error labeled correctly?
- Ensure the error is caught so the program will terminate
- In order to know what type of error was thrown and the location within the program
- To skip over certain blocks of code during execution
- It is not necessary to label errors
π What are the most common modes used when opening a file?
- (a)ppend, (r)ead, (w)rite
- (a)ppend, (c)lose, (w)rite
- (a)ppend, (r)edline, (w)rite
- (s)ave, (r)ead, (w)rite
π What is the data attribute that will return the title of the file?
- File1.close()
- File1.mode
- File1.open()
- File1.name
π What is the command that tells Python to begin a new line?
- \e
- \b
- \q
- \n
π What attribute is used to input data into a file?
- File1.write()
- File1.open()
- File1.close()
- File1.read()
π What python object do you cast to a dataframe?
- set
- tuple
- Dictionary
π How would you access the first-row and first column in the dataframe df?
- df.ix[0,0]
- df.ix[0,1]
- df.ix[1,0]
π What is the proper way to load a CSV file using pandas?
- pandas.from_csv(βdata.csvβ)
- pandas.load_csv(βdata.csvβ)
- pandas.read_csv(βdata.csvβ)
- pandas.import_csv(βdata.csvβ)
π What is the Python library used for scientific computing and is a basis for Pandas?
- Tkinter
- Requests
- datetime
- Numpy
π What attribute is used to retrieve the number of elements in an array?
- a.size
- a.ndim
- a.shape
- a.dtype
π How would you change the first element to β10β in this array c:array([100,1,2,3,0])?
- c[2]=10
- c[1]=10
- c[0]=10
- c[4]=10
π What attribute is used to return the number of dimensions in an array?
-
a.ndim
-
a.shape
-
a.dtype
-
a.size
π What is the result of the following lines of code?
a=np.array([0,1])
b=np.array([1,0])
np.dot(a,b)
- 0
- 1
- array([1,1])
π How do you perform matrix multiplication on the numpy arrays A and B ?
- AB
- A+B
- np.dot(A,B)
π What values does the variable out take if the following lines of code are run?
X=np.array([[1,0,1],[2,2,2]])
out=X[0,1:3]
out
- array([2,2])
- array([1,0,1])
- array([0,1])
π What is the value of Z after the following code is run?
X=np.array([[1,0],[0,1]])
Y=np.array([[2,1],[1,2]])
Z=np.dot(X,Y)
- array([[2,1],[1,2]])
- array([[2,0],[1,0]])
- array([[3,1],[1,3] ])
π Consider the following text file: Example1.txt:
This is line 1
This is line 2
This is line 3
What is the output of the following lines of code?
with open("Example1.txt","r") as file1:
FileContent=file1.read()
print(FileContent)
- This is line 1
This is line 2 This is line 3
- This is line 1
- This
π Consider the following line of code:
with open(example1,"r") as file1:
What mode is the file object in?
- read
- write
- append
π What do the following lines of code do?
with open("Example.txt","w") as writefile:
writefile.write("This is line A\n")
writefile.write("This is line B\n")
- Read the file βExample.txtβ
- Write to the file βExample.txtβ
- Append the file βExample.txtβ
π Consider the dataframe df. How would you access the element in the 2nd row and 1st column?
- df.iloc[1,0]
- df.iloc[2,1]
- df.iloc[0,1]
π In the lab, you learned you can also obtain a series from a dataframe df, select the correct way to assign the column with the header Length to a pandas series to the variable x.
- x=df[βLengthβ]
- x=df[[βLengthβ]]
- x=df.[[βLengthβ]]
π What does API stand for?
- Application Programming Interaction
- Application Programming Interface
- Automatic Program Interaction
- Application Process Interface
π The chart used to plot the cryptocurrency data in the lab is a
- Candlestick Chart
- Line Chart
- Pole Chart
- Point and Figure Chart
π What information are we trying to find for each day in the lab for the chart?
- Open (Last), High (Max), Low (Min), Close (First)
- Open (Max), High (First), Low (Last), Close (Min)
- Open (First), High (Max), Low (Min), Close (Last)
- Open (Min), High (First), Low (Max), Close (Last)
π What is the function of βGETβ in HTTP requests?
- Deletes a specific resource
- Sends data to create or update a resource
- Carries the request to the client from the requestor
- Returns the response from the client to the requestor
π What does URL stand for?
- Uniform Request Location
- Uniform Resource Locator
- Unilateral Resistance Locator
- Uniform Resource Learning
π What does the file extension βcsvβ stand for?
- Comma Separated Values
- Comma Separation Valuations
- Common Separated Variables
- Comma Serrated Values
π What is webscraping?
- The process to extract data from a particular website
- The process to display all data within a URL
- The process to describe communication options
- The process to request and retrieve information from a client
π What are the 3 parts to a response message?
- Start or status line, header, and body
- Encoding, body, and cache
- Bookmarks, history, and security
- HTTP headers, blank line, and body
π What is the purpose of this line of code "table_row=table.find_all(name=βtrβ)"
used in webscraping?
- It will find all of the data within the table marked with a tag βpβ
- It will find all of the data within the table marked with a tag βaβ
- It will find all of the data within the table marked with a tag βh1β
- It will find all of the data within the table marked with a tag βtrβ
π In what data structure do HTTP responses generally return?
- Tuples
- Nested Lists
- JSON
- Lists
π The Python library we used to plot the chart in the lab is
- Pandas
- MatPlotLib
- Plotly
- PyCoinGecko
Final Quiz
π In Python what statement would print out the first two elements βLiβ of βLizzβ?
- print(name[1:2])
- print(name[0:2])
- print(name[2:0])
π If var = β01234567β what Python statement would print out only the odd elements?
- print(var[2::2])
- print(var[1::2])
- print(var[3::1])
π Consider the string Name=βEMILYβ, what statement would return the index of 0?
- Name.find(βIβ)
- Name.find(βLβ)
- Name.find(βEβ)
π In Python what can be either a positive or negative number but does not contain a decimal point?
- str
- int
- float
π What following code segment would return a 3?
- int(3.99)
- str(3.99)
- float(3.99)
π What following code segment would produce an output of β0β?
- 1//2
- 1/2
π In Python 3, what is the type of the variable x after the following: x=2/2 ?
- int
- float
π Whatdata type must have unique keys?
- Tuple
- Dictionary
- List
π What will this code segment βA[0]β obtain from a list or tuple?
- The first element of a list or tuple
- The third element of a list or tuple
- The second element of a list or tuple
π What does the split() method return from a list of words?
- The list of words in a string separated by a delimiter
- The list of words in reverse order
- The list of words separated by a colon
- The list in one long string
π Tuples are:
- Not mutable
- Unordered
- Not indexed
- Mutable
π What is a collection that is unordered, unindexed and does not allow duplicate members?
- Set
- List
- Tuple
π What value of x will produce the following output?
How are you?
x=
if(x!=1):
print('How are you?')
else:
print('Hi')
- x=β7β
- x=1
- x=6
π Why is the βfinallyβ statement used?
- Execute the remaining code no matter the end result
- Only execute the remaining code if one condition is false
- Only execute the remaining code if no errors occur
- Only execute the remaining code if an error occurs
π Given the function add shown below, what does the following return?
def add(x): return(x+x) add(β1β)
- β2β
- 2
- β11β
π What function returns a sorted list?
- sorted()
- lower()
- find()
- sort()
π 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 - error: cannot multiply a string by an integer
- 11
22
33
π What is the output of the following?
for i in range(1,5): if (i!=2): print(i)
- 1
3
4 - 2
- 1
2
3
4
π Consider the class Rectangle, what are the data attributes?
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()
- self.height, self.width,self.color
- drawRectangle
- init
π What line of code would produce the following: array([0, 0, 0, 0, 0]) ?
- a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a-b
- a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a*b
- a=np.array([0,1,0,1,0]) b=np.array([1,0,1,0,1]) a+b
π What is the result of the following lines of code?
a=np.array([1,1,1,1,1]) a+10
- array([1,1,1,1,1])
- array([10,10,10,10,10])
- array([11, 11, 11, 11, 11])
π 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β
- This line of code does not select the headers
- βArtistβ, βLengthβ and βyβ
π What is the method readline() used for?
- It helps to read one complete line from a given text file
- It reads the entire file all at once
- It reads 10 lines of a file at a time
π What mode over writes existing text in a file?
- Write βwβ
- Read βrβ
- Append βaβ
π What are the 3 parts to a URL?
- Put, route, and get
- Scheme, internet address, and route
- Get, post, and scheme
- Block, post, and route