1.
What is the output of the following code?
>>> spam, ham = 1 , "ham"
>>> spam *= 3
>>> ham *= 3
>>> spam, ham
2.
What is the output of the following code?
def spam (x, sum):
return sum if x == 0 else sum + spam(x -1 , sum)
print(spam( 3 , 0 ))
3.
What is the output of the following code if spam.py is run?
# spam.py
print( "spam" , end= ' ' )
import ham
# ham.py
import eggs
print( "ham" , end= ' ' )
# eggs.py
print( "eggs" , end= ' ' )
4.
What is the output of the following code?
total = 0
for i in range( 1 , 4 ) :
i += 2
total += i
else:
total += 100
print(total)
5.
Which option(s) will return Ham ? (Select 3)
6.
What is the output of the following code?
7.
What is the output of the following code if the user enters 1 on the first prompt and 2 on the second prompt?
a = input( "Enter first number:" )
b = input( "Enter second number:" )
print(a + b)
8.
What is the output of the following code?
f = lambda x: 10
print(f( 20 ))
9.
How do you call the function ham() saved as spam.py below? (Select 2)
def ham ():
print( "Hello World" )
10.
What is the output of the following code?
spam = { 'z' : 'x' , 'x' : 'y' , 'y' : 'z' }
ham = 'x'
for x in range(len(spam)):
ham = spam[ham]
print(ham, end= "" )
11.
What is the expected output of the following snippet?
a=2
if a>0:
a+=1
else:
a-=1
print(a)
12.
What is the output of the following code?
x = 3
while x > 0 :
print(x, end= '' )
x //= 2
13.
What is the output of the following code? (ignore the || in the options)
spam = {}
spam[ 1 ] = [ 1 , 2 ]
spam[ 2 ] = [ 3 , 4 ]
print(type(spam))
14.
Which option will create a tuple ham equal to ("brown", "fox") using the code below ?
(Select 3)
spam = ( "the" , "quick" , "brown" , "fox" )
15.
What will be printed in the following code?
spam = """"""
ham = """
"""
print(spam, ham)
16.
How will you call the code below if you want to print 1, 2, 3? (Select 3)
def spam (a, b, c= 3 ):
print(a, b, c)
17.
What is the output of the following code?
x = 'x'
def main ():
y = 'y'
def spam ():
print(x, y, z)
return
spam()
z = 'z'
if __name__ == "__main__" :
main()
18.
What is the output of the following code?
d = { 'zero' : 0 , 'one' : 1 , 'three' : 3 , 'two' : 2 }
for k in sorted(d.keys()):
print(d[k], end= ' ' )
19.
What is the output of the following code?
t = True
f = not t
t = t or f
f = t and f
t, f = f, t
print(t, f)
1 out of 4
20.
Suppose you want to join train and test dataset (both are two numpy arrays train_set and test_set) into a resulting array (resulting_set) to do data processing on it simultaneously.
This is as follows:
train_set = np.array([1, 2, 3])
test_set = np.array([[0, 1, 2], [1, 2, 3]])
resulting_set --> [[1, 2, 3], [0, 1, 2], [1, 2, 3]]
How would you join the two arrays?
Note: Numpy library has been imported as np
21.
Suppose you are given a dataframe df:
df = pd.DataFrame({'Click_Id':['A','B','C','D','E'],'Count':[100,200,300,400,250]})
Now you want to change the name of the column ‘Count’ in df to ‘Click_Count’.
So, for performing that action you have written the following code.
df.rename(columns = {'Count':'Click_Count'})
What will be the output of print statement below?
print (df.columns)
Note: Pandas library has been imported as pd.
22.
I have built a simple neural network for an image recognition problem. Now, I want to test if I have assigned the weights & biases for the hidden layer correctly. To perform this action, I am giving an identity matrix as input. Below is my identity matrix:
A = [ 1, 0, 0
0, 1, 0
0, 0, 1]
How would you create this identity matrix in python?
Note: Library numpy has been imported as np.
23.
Suppose you are given a monthly data and you have to convert it to daily data.

For this, first you have to expand the data for every month (considering that every month has 30 days)
Which of the following code would do this?
Note: Numpy has been imported as np and dataframe is set as df.
24.
Which of the following will be the output of the below print statement?
print(df.val == np.nan)
Assume, you have defined a data frame which has 2 columns.
import numpy as np
import pandas as pd
df = pd.DataFrame({'Id':[1,2,3,4],'val':[2,5,np.nan,6]})
25.
Suppose you are given a data frame df:
df = pd.DataFrame({'Click_Id':['A','B','C','D','E'],'Count':[100,200,300,400,250]})
In many data science projects, you are required to convert a dataframe into a dictionary. Suppose you want to convert “df” into a dictionary such that ‘Click_Id’ will be the key and ‘Count’ will be the value for each key.
Which of the following options will give you the desired result?
Note: Pandas library has been imported as pd
26.
How would you read data from the file using pandas by skipping the first three lines?
Note: pandas library has been imported as pd
In the given file (email.csv), the first three records are empty.
,,,
,,,
,,,
Email_Address,Nickname,Group_Status,Join_Year
aa@aaa.com,aa,Owner,2014
bb@bbb.com,bb,Member,2015
cc@ccc.com,cc,Member,2017
dd@ddd.com,dd,Member,2016
2 out of 4
27.
What will happen if spam.py is run?
# spam.py
try :
print(x)
except :
print( "An exception occurred" )
28.
What is the output of the following code?
#spam.txt
spam ham eggs
#spam.py
f = open( 'spam.txt' , 'r' )
if 'eggs' in f:
print( 'Eggs found' )
else:
print( 'Eggs not found' )
29.
What is the output of the following code?
try:
print( "1" , end= '' )
raise Exception
print( "2" , end= '' )
except BaseException:
print( "3" , end= '' )
else:
print( "4" , end= '' )
finally:
print( "5" )
30.
What is the output of the following code?
class Ham :
v = 1
def v0 (self):
return self.v
class Spam (Ham):
v = 2
s = Spam()
h = Ham()
print(s.v0(), h.v0())
31.
Which of the option(s) is valid given the code below?
class Spam :
''' This is class Spam '''
pass
32.
What is the output of the following code?
class Foo :
bar = 'spam'
f1 = Foo()
f2 = Foo()
f2.bar = 'ham'
Foo.bar = 'eggs'
print(f1.bar, f2.bar, Foo.bar)
33.
What is the output of the following code?
>>> [ 2 ** x for x in range( 5 )]
34.
What is the output of the following code?
def spam (x):
def ham (y):
return x * y
return ham
f = spam( 2 )
print(f( 3 ))
35.
What is the output of the code?
for spam in open( 'spam.txt' , 'rt' ):
print(spam, end= '' )
given spam.txt
This is LINE 1
This is LINE 2
36.
What is the result of the following code? (Select 2)
with open( 'spam.txt' , 'r+' ) as file:
line = file.read()
file.write(line)
given spam.txt
12345
3 out of 4
37.
You have the following dataset.

Which Level of Detail (LOD) expression should you use to calculate the grand total of all the regions?
38.
You have a line chart on a worksheet.
You want to add a comment to March 2020 as shown in the following visualization.

What should you do?
39.
How to set a line width in the plot given below?

For the above graph, the code for producing the plot was
import matplotlib.pyplot as plt #Line One
plt.plot([1,2,3,4]) #Line Two
plt.show() #Line Three
40.
What should be written in-place of “method” to produce the desired outcome?
Given below is dataframe as df:

Now, you want to know whether BMI and Gender would influence the sales.
For this, you want to plot a bar graph as shown below:

The code for this is:
var = df.groupby(['BMI','Gender']).Sales.sum()
var.unstack().plot(kind='bar', method, color=['red','blue'], grid=False)
4 out of 4