Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

1. What is the output of the following code?

for i in range(0,10,2.5):
print(i)
A. 0 2.5 5 7.5
B. 0 2 4 6 8
C. 0 2.5 5 7.5 10
D. Error.

2. What is the output of the following code?


var1= 1
var2 = 2
var3 = '3'
print(var1 + var2 + var3)
A. 6
B. 33
C. 123
D. Error

3. What is the output of the following code?


Listl = [1, 'cse', 'rgukt']
List2 = [1, 'cse' 'rgukt']
print(List1 == List2)
print(List1 is List2)
A. True True
B. True False
C. False False
D. False True

4. What is the output of the following code?


a = True b =
False c =
True
if not a or b:
print('a')
elif not a or not b and c:
print('b')
elif not a or b or not b and a:
print('c')
else:
print('d')
A. b
B. a
C. d
D. c

5. What will be the result of 7^10 in python?


A. 2
B. 13
C. 15
D. None

6. Which of the following is a reserved keyword in python?


A. else
B. assert
C. raise
D. All

7. What is the associativity of operators with the same precedence?


A. Depends on Operators
B. Left to Right
C. Machine Dependent
D. Right to Left

8. What is the output of the following program?


data = 50
try:
data = data/5
except ZeroDivisionError:
print('Cannot divide by 0', end =")
else:
print('Division successful ', end =")
try:
data = data/0
except:
print('Inside except block ', end = ")
else:
print('DADA', end =")

A. Division successful Inside except block


B. Cannot divide by 0 Inside except block DADA
C. Cannot divide by 0
D. Cannot divide by 0 DADA

9. What is the output of the following Python Code Snippet ?


txt = "Hello! CSE "
num = 3
while num > 0:
print(text)
num =num-1
A. Prints Nothing
B. Infitie Times of Hello! CSE
C. Hello! CSEHello! CSEHello! CSE
D. Hello! CSEHello! CSEHello! CSEHello! CSE

10. What is the result of the following statement?


print(chr(ord('E')-2),chr(ord('P')+3), chr(ord('A') + ord('e')-ord('a')))
A. EPA
B. DSP
C. CSE
D. Error.

11. Which of the following statement prints smith\exam 1\test.txt?


A. print("smith\\exam 1 \\test.txt")
B. print("smith"\exam1"\test.txt")
C. print("smith\exam1\test.txt")
D. print("smith\"exam1\"test.txt")

12. What happens when the following python script is executed?


L = [97, 'DADA', True, 1]
T = (77, 'DHONT', False, 2)
for i in range(len(L)):
if L[i]:
L[i] = L[i] + T[i]
else:
T[i] = L[i] + T[i]
break

A. L & T both changes


B. Only T Changes
c. Error
D. None

13 For m = [[x, x + 1, x + 2] for x in range(1, 9, 3)], m is ________


A. [[1, 2,3], [4, 5,6] ,[7,8, 9]]
B. [0, 1, 2, 1, 2, 3, 2, 3, 4]
C. [1,2,3,4,5,6, 7,8, 9]
D. [[0,1,2] ,[1 2,3],[ 2, 3, 4]]

14. Suppose t = (1, 2, 4, 3), t[1 : -1] is _______


A. (2, 4)
B. (1, 2, 4, 3)
c. (1, 2, 4)
D. (1, 2)

15. What is the output of the following program?


print('The sum of {1} and {0} ts {2}'. format(2, 10, 12))
A. The sum of 2 and 10 is 12
B. The sum of 10 and 2 is 12
C. Error
D. None of the mentioned
16. What is the output of the following program?
t=tuple('DADA')
a,b,c,d=t
a,b=b,a c,d=d,c
t=(a,b,c,d)
print(" .join(t))
A. DADA
B. DDDD
C. AAAA
D. ADAD

17. Which of the following function gets a space-padded string with the original string
left-justified to a total of width columns?
A. join(seq)
B. len(string)
C. isupper()
D. ljust(width[,fillchar])

18. The expression "Good"+1+2+3evaluates to


A. Good123
B. Good6
C. Illegal expression
D. Good 123

19. Which of the following does the below code do?


s=input()
print (' '.join(s.split(' ')[::-1]))
A. Prints the reverse of a string
B. Prints the words of a string in reverse order.
C. Prints reverse of each word in the given string
D. None

20. list1 = [11, 2, 23] and list2 = [2, 11, 23], list1 == list2 is______
A. True
B. False
C. Can't Say
D. None

21. Which of the following methods will the return the list of the all matches regarding
the given Regular Expression?
A. re.findall()
B. re.search()
C. re.subn()
D. None

22. Which of the following is a expression to validate an IP address?


A. r '\d {3} \.\d{3} \.\d{3} \.\d{3}'
B. r '^\d {3} \.\d{3} \.\d{3} \.\d{3}$'
C. r '\d {3} \.?\d{3} \.?\d{3} \.?\d{3}'
D. None

23. What is the output of the following program?


re.sub('morning', 'evening', 'good morning')
A. 'good'
B. 'good evening'
C. 'morning'
D. 'evening'

24. Which of the following is the regular expression that validates the given input as a
number or not? (Number should be any real number)
A. r '[0-9]+(\.[0-9]+)?'
B. r '[0-9]+(\.[0-9])+?
C. r '[0-9]*(\.[0-9]+)?
D. None

25. Which of the following creates a pattern object?


A. re.create(str)
B. re.regex(str)
C. re.compile(str)
D. None

26. What is the output of the following?


sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print (matched. groups())
A. ('w', 'a', 'h')
B. ('we are humans')
C. ('we are' , 'humans')
D. ('we’, ‘are' , 'humans')

27. Which of the following character is used to match any whitespace character?
A. \s
B. \S
c. \z
D. None

28. What will be the output of the following Python code?


re.split('\W+', 'Hello, hello, hello.')

A. ['Hello', 'hello', 'hello', '.']


B. ['Hello, 'hello', 'hello' ]
C. ['Hello', 'hello', 'hello', "]
D. ['Hello', 'hello', 'hello.']

29. Which of the following expression 1s used to list all the student IDs of 'R14' batch in
the given file?
A. r '\b(R|r)14\d {4}\b'
B. r '(R|r)14\d{4}'
C. r '[R|r]14\d {1-3}'
D. r'^(R|r)14\d{4}$'
30. The character Dot (that is, '.') in the default mode, matches any character other
than________
A. newline
B. caret
C. percentage symbol
D. ampersand

31. Which of the method will be used to find the difference of days between two given
dates?
A. now()
B. strftime()
C. Strptime()
D. None

32. Which of the following will given current time of the system?
A. time.localtime()
B. datetime.today()
C. datetime.now()
D. All

33. Which of the following will print the second Saturday of a given month?

A. dt=datetime.strptime("%b %Y")
print((dt-timedelta(weeks=1, days=(dt.weekday()-
5)%7)).strftime("%b %d %Y"))

B. dt=datetime.strptime("%b %Y)
print((dt+timedelta(days=7+(5-dt.weekday())%7)).strftime("%b %d %Y"))

C. dt=datetime.strptime("%b %Y)
print((dt+timedelta(days=(5-dt.weekday())%7)).strftime("%b %d %Y"))

D. dt=datetime.strptime("%b %Y)
print((dt-timedelta(days=(dt.weekday()-5)%7)).strftime("%b %d %Y"))

34. What will be the output of the following Python code?


import datetime
d=datetime.date(2016,24,12)
print(d)

A. 24-12-2016

B. Error

C. 2016-12-24

D. 2016-12-24

35. Which represents the outcome of the given statement ?


print((datetime.today()).strftime("%d %b %y - %H:%M %p))
A. 15 Feb 20 -- 09:15 AM
B. 15 Feb 2020 -- 09:15 AM
C. 15 Feb 20 -- 09:15 AM
D. Feb 15 2020 -- 09:15

36. Which of the following converts the input string , say ip = 'Apr 2,2011 22.15" into
datetime object?
A. datetime.strptime(ip, '%b %d,%Y %I.%M)

B. datetime.strptime(ip, '%b %d,%Y %M.%M)

C. datetime.strptime(ip, '%b %d,%y %H.%M)

D. datetime.strftime(ip, '%b %d,%Y %I.%M)

37. Which of the following will print the date of last Friday?

A. dt=datetime.today()
print((dt - timedelta(days=(dt.weekday()-4)%7)).strftime("%b %d %Y"))

B. dt=datetime.today()
print((dt+ timedelta(days=(dt-weekday()-4)%7)).strftime("%b %d %Y"))

C. dt=datetime.today()
print((dt+ timedelta(days=(dt.weekday()+4)%7)).strftime("%b %d %Y"))

D. dt=datetime.today()
print((dt - timedelta(days=(dt.weekday()+4)%7)).strftime("%b %d %Y"))

38. Which of the statement will give you the day of week for the given date, 'd'?
A. d.strptime("%B")
B. d.weekday()
C. d.strftime("%b")
D. None

39. Which of the following represent the hours in 12 Hour format?


A. %I
B. %p
C. %h
D.%H

40.Which of the following can be used to get a day number in a week for given date, say
"d'
A. d.weekno()
B. d.dayno()
C. d.day()
D. None

41. What is the output of the following code?


import numpy as np
a = np.array([[1,2,3],[0,1,4]])
b = np.zeros((2,3), dtype=np.int16) c =
np.ones((2,3), dtype=np.int16)
d=a*b@c
print (d[1,2] )

A.8
B.1
C. 5
D.0

42. What is the output of the following code?


import numpy as np
a =np.array([[0, 1, 0], [1, 0, 1]))
a+=3
b=a+3
print (a[1,2] + b[1,2])
A.6
B.5
C. 0
D. 11

43. Which of the following counts the number of elements in Numpy array?
A. Size()
B. Array.ndim
C. Return()
D. Shape()

44. What is/are the advantage(s) of Numpy Arrays over classic python lists?
A. Insertion, Concatenation and deletion are faster
B. It has better support for mathematical operations
C. They consume less memory
D. All

45. Which of the following is the correct syntax for the 'reshape'function in Numpy array
python?
A. reshape(array,shape)
B. array .reshape(shape)
C. reshape(shape,array)
D. reshape(shape)

46. If you have a numpy array, in a variable 'rkv', how would you access the data item at
the 5th column, 2nd row?
A. rkv(1,5)
B. rkv[1,5]
C. rkv(2,4)
D. rkv[1,4]

47. What does 'numpy.array(list)' do?


A. It converts array to array
B. Error
C. It converts array to list
D. It converts list to array

48. What is the output of the following python script?


import numpy as np
a =np.array([1,2,3,5,8]) b =
np.array([0,3,4,2,1])
c=a+b c=c*a
print (c[2])
A. 12
B. 7
C. 10
D. 21

49. What is the result of following code?


import numpy as np import
numpy.linalg
A =np.array([[2, 1], [1, 2]])
B =numpy.linalg.inv(A)
A@B
A. array([[-5, -4] , [-4 , -5]])
B. array([[5, 4] , [4 , 5]]) C.
Array([[0, 1] , [1, 0]])
D. Array([[1. , 0.] , [0. , 1.]])

50. What is the output of the following code?


import numpy as np
a =np.array([[0, 1, 2], [3, 4, 5])
b =a.sumfaxis=1)
print (b)
A. [3 5 7]
B. (3 12]
C. 3
D. 12

51. Which of the following method may be used to handle the missing data?
A. fillna()
B. notnull()
C. All
D. isnull()

52. From the given assignment, what is the number of students that are included to
derive the cutoffs for the subject of 'Mathematics'?
A. 1107
B. 1096
C. 1098
D. 1097
53. What is the output of the following?
cities = {"London": 8615246, "Berlin": 3562166, "Madrid": 3165235, "Rome":
2874038,
"Paris": 2273305, "Vienna": 1805681, "Bucharest":1803425, "Hamburg":
1760433,
"Budapest": 1754000,"Warsaw": 1740119,"Barcelona":1602386, "Munich":
1493900, "Milan": 1350680}
my_cities = ["London", "Paris", "Zurich", "Berlin", "Stuttgart", "Hamburg"]
my_city_series = pd.Series(cities, index=my cities)
print(my_city_series)

A. London 8615246
Paris 2273305
Zurich 0
Bertin 3562166
Stuttgart 0
Hamburg 1760433

B. London 8615246
Paris 2273305 Berlin
3562166
Hamburg 1760433

C. London 8615246
Paris 227330S
Zurich NaN
Berlin 3562166
Stuttgart NaN
Hamburg 1760433

D. None

54. From the given assignment, which of the following subject has minimum average
Internal Marks(for 40)?
A. Mathematics
B. IT
C. Physics
D. Chemistry

55. Which of the following statements adds new column representing type 1/1 of player
to the dataframe given below?
my_fav =pd.DataFrame{ { 'Name' :
('Dada','Yuvi'','Sehwag','Hitman','Virat','Zaheer'),
'BattingAvg' : [42,38,41,48,59,12],
'Wickets' : [133,102,80,5,3,320] ))
def player_type(data):
if data['BattingAveg'')] > 30 and data['Wickets]>100:
return 'Allrounder'
elif data['BattingAvg') > 30 and data['Wickets]<100:
return 'Batsman'
else:
return 'Bowler

A. my_fav['PlayerType']=player_type(my_fav)

B. my_fav['PlayerType']=player_type.apply(my_fav)

C. my_fav['PlayerType']=my_fav.player_type()

D. my_fav['PlayerType']=my_fav.apply(player_type)

56. Which of the following method is used to combine a set of Series object (say
$1,S2,S3) to a dataframe?
A. pd.combine(S1,S2,S3)

B. pd.add(S1,S2,S3)

C. S1+S2+S3

D. None

57. Which of the following statement that modifies the given DataFrame by sorting with
reference to given column in descending order.

A. Df.sort_values(inplace=True)

B. Df.sort_values(by = 'column_name', ascending=False,inplace=True)

C. Df.sort(ascending=False,inplace=True)

D. Df.sort_values(by= 'column_name')

58. Which of the following statement is wrong in deriving corresponding


cutoff(Assuming index is reset from 0)?

A. None

B. cutoff['C']=max(60,min(50,marks.iloc[ceil(80*n/100)-1]))

C. cutoff['A']=min(80,min(70,marks.loc[ceil(25*n/100)-1)))

D. cutoff['EX']=min(90,max(80,marks.loc[ceil(5*n/100)-1)))

59. From the given assignment, which of the following subject has highest number of 'B'
grades?

A. Telugu

B. Mathematics

C. Chemistry
D. IT

60. What is the output of the following code snippet?


my_cities = ["London", "Paris", "Zurich", "Berlin", "Stuttgart", "Hamburg"]
my_city_series = pd.Series(cities, index=my_cities)
print(my_city_series.isnull())

A.London False B. London True


Panis False Paris True
Zurich True Zurich False
Berlin False Berlin True
Stuttgart True Stuttgart False
Hamburg False Hamburg True

C. London False D. London True


Paris True Paris False Zurich True Zurich False Berlin False
Berlin True
Stuttgart False Stuttgart True Hamburg False Hamburg
False

You might also like