This Book Should Be Used ONLY As A Guideline To Practice What Is Taught in Class. Exam Questions Will Tend To Change, But Have A Similar Pattern
This Book Should Be Used ONLY As A Guideline To Practice What Is Taught in Class. Exam Questions Will Tend To Change, But Have A Similar Pattern
Page 1 of 67
NMUISA Academic Affairs 2021/2022
Credits
Auxilium was created by the NMUISA Academics Affairs to ensure that all students have equal access to
relevant course materials, including high yield points of the exam.
This idea was proposed by President Shan Hemachandra, taken up by Director Aruthnie Jayamaha and the
Academics Affairs to create the book series.
This book (First Year Second Semester) was compiled by the collective efforts of
Nishant Singh Bhati , Rakshita Bharti , Sanjeevini Gogoi and Nisha Kaur .
Page 2 of 67
NMUISA Academic Affairs 2021/2022
Information Technology
MCQ
2. "+" means "concatenate" if 10. The break statements ends the current
something is a number loop and jumps to the statement
⑧ a. True immediately following the loop
b. False a. True
b. False
3. Strings can be enclosed in single
quotes (‘...’) or double quotes (“...”) 11. Python Variable Name is case
with the same result. sensitive
Ia. True a. True
b. False b. False
4. Strings can be indexed (subscripted),
with the first character having index 1 12. The output of the expression
a. True “12//5+3*((7%3)-4)” is -4.
Ib. False a. True
b. False
5. “=” is a Comparison Operator, which
means "equal to". 13. The following codes will draw a
⑧
a. True black line by matplotlib.
b. False import matplotlib.pyplot as plt
plt.plot ([1,2,3,4])
6. The following line of code will set a. True
text labels of x axis. b. False
xticks([0, 1, 2]) , [‘January’ ,
'February’ , 'March'] , (rotation=20) 14. In two-way Decision, we must choose
a. True one or the other path but not both
b. False a. True
b. False
7. The input() function returns a integer
a. True 15. Matplotlib.pyplot.pie() function will
b. False make a pie chart of array x. The
fractional area of each wedge is given
8. Indices of strings may also be by x/sum(x)
negative numbers , to start counting a. True
from the right b. False
a. True
b. False
Page 3 of 67
NMUISA Academic Affairs 2021/2022
16. Lists might contain items of different d. 10~99
types, but usually the items all have
the same type
a. True 22. Write what it prints out after the
b. False below code being executed.
17. The string should be enclosed in lst_a=[1,2,3,4,5]
double quotes if the string contains a While len(lst_a)>0:
single quote and no double quotes Print (lst_a.pop(), end = ‘,’
a. True
b. False a. 5,4,3,2,1,
b. 5,
18. Each pyplot function makes some c. 5
change to a figure; d. 5,4,3,2,1
Eg. creates a figure , creates a plotting
area in a figure, plots some lines in a 9.25
23. range(2,8,3) include _________?
plotting area, decorates the plot with a. 2 8 3 Code: print (list range (2,8,311)
labels, etc b. 2 3 5
a. True c. 2 5 8
b. False d. 2 5
Page 4 of 67
NMUISA Academic Affairs 2021/2022
26. _______ can’t be a variable name in 30. What does it print out after the below
python? code being executed?
a. _bmi a=1
b. 5paint b=3
c. Type_2 If a>2:
d. Height print(“b is” , b)
If b>2:
27. What does it print out after the below c=a+b
code being executed? Print (“c is” , c)
else:
a=1 Print (“a is ” , a)
b=3
If a>2: a. c is 4
If b>2: b. a is 1
c=a+b c. nothing
Print (“c is” , c) d. b is 3
else:
Print (“a is ” , a) 31. Which of the following works without
any error ?
a. c is 4
b. Nothing a. var ‘123’* 5
c. a is 1 b. var ‘xyz123’* 10.5
d. b is 3 c. var ‘xyz123’* ‘5’
d. var ‘123’* 5.0
28. What does it print out after the below 32. What does it print out after the below
code being executed ? code being executed?
a. 5
b. 7 x=3
c. 9 y=2
d. 2 While x<10:
If y%x = =2:
29. Whose value does not equal to 4.0 print (y)
a. 16**1/2 x=x+y
b. pow(1,0.5) y=y+1
c. pow(16,1/2)
d. 16**0.5 a. 2
b. 1
c. 3
d. 4
Page 5 of 67
NMUISA Academic Affairs 2021/2022
33. What’s the results of the following 37. Which line of code can realize the
code? following requirements.
Print (‘aaZ’ < ‘aaz’)
There is a test, txt file, open this file
a. Yes in append mode, and use variable f to
b. 1 receive the return value of the file
c. True
d. Y a. f= open(“test.txt”, “a”)
b. f= open(“test.txt”, “r”)
34. The function of the following codes c. f= open(“test.txt”, “w”)
is : open the test, TXT file, use the d. f= open(“test.txt”, “r+”)
variable f to receive the return value
and close the file.
Please fill in the line (1) top complete
the above function
f = open(“test.txt” , “r”)
content = f.read()
( line(1) )
a. content.shutoff()
b. f.close()
c. content()
d. f.shutoff()
a. 1
b. True
c. 0
d. False
a. Aabb
b. Abc
c. Aabbcc
d. abb
Page 6 of 67
NMUISA Academic Affairs 2021/2022
SAQ
42. Given : s = ‘Welcome to China!’ .
38. my_str = ‘Python Rules!’ What is the What is the value of s[ : 6 : 2 ]?
value of (Quotation marks not included)
my_str.upper()find(‘T)?
X = [1,2,3,4,5,6]
Y = [82, 84, 89, 76, 94, 74]
fig = plt.figure()
plt.( 1 )(X,Y,0.4,color=”green”)
plt.xlabel(“Classes”)
plt.ylabel(“ 2 ”)
plt.title (“The average score of six
classes”)
plt.show()
1=
2=
Page 7 of 67
NMUISA Academic Affairs 2021/2022
46. Please fill in the ( 1 ) to get the figure 49. _______ is printed by the following
of BMI of every person : codes in the first line.
_______ is printed by the following
Import numpy as np codes in the second line.
Import matplotlib.pyplot as plt _______ is printed by the following
X1 = np.arange(4) codes in the third line
height = np.array([1.65, 1.6, 1.7, 1.76])
weight= np.array([62, 50, 65, 65]) x=5
bmi = weight/(height**2) If x == 5 :
plt.xticks(x1, (‘Ankit’ , ‘Hans’ , ‘Joe’ , print(‘Equals 5’)
‘Flaco’)) If x > 4 :
plt.bar( 1 , color = “blue”) print(‘Greater than 4’)
If x > 5:
print(‘Greater than 5’)
If x !=6 :
print(‘Not equal 6’)
Page 8 of 67
NMUISA Academic Affairs 2021/2022
LAQ
53. Write the whole paragraphs of program to sum up all the numbers between the input lowerbound and
upperbound (including both bounds) according to the provided code .
For example :
Pls input the lowerbound : 5
Pls input the upperbound : 25
The program is :
54. Given the values of height, weight, and name of four guys are defined as follows.
Page 9 of 67
NMUISA Academic Affairs 2021/2022
Chaoxing Questions 8 ) Predict the outcomes of the following
expressions, given a = 5, b = 4, and c = 4.
1)Predict the output: (2**2)**3 b**c
Ans-64 Ans-256
2)my_int = 5
my_int = my_int + 3 9)Assignment:
print(my_int) my_var1 = 7.0
If you execute the three lines of code, what my_var2 = 5
will be printed? print(my_var1 % my_var2)
If you execute the three lines of code, what
Ans-8 will be printed?
x=4 Ans- D
y=5
print (x//y)
Ans-0
Ans-2
Ans-21
Page 10 of 67
NMUISA Academic Affairs 2021/2022
12)write what it prints out after the below B.Medium
code being excuted.
C.Large
x=6
D.Nothing
if x > 1 :
print('More than 1')
Ans-B
if x > 10 :
print('more than 10')
15)write what it prints out after the below
A.More than 1 code being excuted.
C.Bigger n=5
Smaller while n > 0 :
n=n–1
D.Nothing print(n)
Ans-B A.5
B.4
C.0
14)write what it prints out after the below
D.-1
code being excuted.
Ans-C
x=6
if x < 2 :
print('Small')
elif x < 10 :
print('Medium')
else :
print('Large')
A.Small
Page 11 of 67
NMUISA Academic Affairs 2021/2022
17)What does it print out after the below
code being excuted? 20)What does it print out after the below
n=5 code being excuted?
while n < 0 : n=5
n=n–1 while n >= 5 :
print(n) n=n–1
print(n)
A.5
B.4 A.5
C.0
D.-1 B.4
Ans-A C.1
C.4 Ans- C
3
2
D.2
3
4
Ans-C
Page 12 of 67
NMUISA Academic Affairs 2021/2022
22 ) Given user input of 5, what does the 24)The output of the statement“print
program print? (round(3.5))”is_________.
A. 3
number_str = input("Enter an int:")
number = int(number_str)
count = 0 B. 3.0
while number > 0:
if number % 2 == 0: C.4
number = number // 2
elif number % 3 == 0:
number = number // 3 D.4.0
else: # Line 1
number = number - 1 Ans-C
count = count + 1
print("Count is: ",count)
25)The output of the statement“print
A.Count is: 1 (int(3.8)+abs(-4)+round(1.8))”is_________.
A. 7
B.Count is: 2
B. 8
C.Count is: 3
C. 9
D.Count is: 4
Ans- D D. 10
Ans-C
23)What does the program print?
26)Whose value does not equal to 3.0?
the_sum = 0
extra = 0 A. 9**0.5
for number in [1,2,3,4,5,6]:
if number%2 and not number%3: B. 9**1/2
the_sum = the_sum + number
print(the_sum)
C. pow(9,1/2)
A.3
D. pow(9,0.5)
B.5
Ans-B
C.9
27) range(5) is _________
D.12 A. [0,1,2,3,4,5]
Ans-A B. [0,1,2,3,4]
C. [1,2,3,4]
D.[1,2,3,4,5]
Ans-B
Page 13 of 67
NMUISA Academic Affairs 2021/2022
28)What’s range of the random number 31)Given the function make odd, what are
created by the expression the results of the function invocation(print
(int(random.random()*900+100)) ? statements)?
A. 0~900
B. 100~900 def make_odd(n):
C. 0~999
D. 100~999 return 2*n + 1
Ans-D
n=3
29)What kind of features does not
print (make_odd(n))
functions provide?
A. Divide-and-conquer problem A. 3
solving B. 4
B. Abstraction and reuse C. 7
C. Simplification and D. 8
readability
D. Increase computing speed Ans-C
and decrease processing time
32)Given the function make odd, what are
n=3
A. 4 B. 4
B. 7 C. 7
C. 15 D. 8
D. 16
Ans-D
Ans-C
Page 14 of 67
NMUISA Academic Affairs 2021/2022
34)Given x = 'waterwater', what is returned
32)Given the function make odd, what are
by x.replace('w','c')?
the results of the function invocation(print
A. watercater
statements)?
B. caterwater
def make_odd(n): C. catercater
Ans- C
n=3
35) Which of the following works without
print (1+make_odd( make_odd(3)))
any error?
A. 4
A. var = 'xyz'* 10.5
B. 7
B. var = 'xyz' * '5'
C. 15
C. var = 'xyz' * 5
D. 16
D. var = 'xyz' * 5.0
Ans-D Ans-C
What is the value of my_str? odd length: Write an expression to print the
B. Hello A. x(len(x)/2)
C. Jllo B. x[len(x)/2]
D. Je C. x[len(x)//2]
D. x(len(x)//3)
Ans-A
Ans-C
Page 15 of 67
NMUISA Academic Affairs 2021/2022
37)Given the following variable assignments: 40 ) Given the string S = "What is your
A. Y B. N
B. True C. null
C. 1 D. error
D. Yes Ans-A
Ans-B
42) What output is produced by Line 1?
39 ) What does the following Python
A. Bbcc
B. abb
C. abc
A. bbcc
D. aabb
B. abb
Ans-C
C. abc
D. aabb
Ans-B
Page 16 of 67
NMUISA Academic Affairs 2021/2022
48)my_str = 'Python Rules!'
43)a_str = 'spam' What is the value of a_str[1]
print (my_str.lower().find('o') ) # Line 1
What output is produced by Line 1 ?
= 'l' ?
Ans-4
A. slam
B. TypeError 49)a_str = 'He had the bat' What is the value
of a_str.find('t',8)
C. spam
D. warning Ans - 13
44)What does the following Python Program There is a test. txt file, open this file in
append mode, and use variable f to
print out?
receive the return value of the file
Ans - B
Page 18 of 67
NMUISA Academic Affairs 2021/2022
57) For list of a=[1,2,3,4,5,6,7,8,9], which 60) What is the output of the following codes?
indexing is wrong?_________ lst_A =['aaa','bb','c',1,2,3,5.2,True]
A.a[0] print(lst_A[3]+lst_A[4]+lst_A[5])
B.a[9]
C.a[-2] Ans - 6
D.a[len(a)-1]
61) What is the output of the following codes?
Ans - B lst_A =['aaa','bb','c',1,2,3,5.2,True]
Hint :: The length of the list is 9, and the print(sum(lst_A[3:7]))
max index of the list is 8.
Ans - 11.2
58) What is printed out after the following
code being excuted. 62) What is the output of the following codes?
a=['apple','banana','orange','peach'] print lst_A =['aaa','bb','c',1,2,3,5.2,True]
("I like ",a[0],"and",a[-1] ) lst_B = lst_A[3:-1]
print(sum(lst_B)/len(lst_B))
A.I like apple and peach
B.I like apple "and" peach Ans - 2.8
C.I like banana and orange
D.I like banana "and" orange 63) What is the output of the following
codes?
Ans - A lst2= [1,2]*3
print(lst2)
59) Giving a=[2,3] in [1,2,3,4], a is
__________. Ans - [1,2,1,2,1,2]
A.0
B.1 64) What is the output of the following codes?
C.True lst1=[1, 2, 3, 4, 5, 6]
D.False print(print(lst1.pop() ,lst1.pop()))
Ans - D Ans - 6 5
Hint :: There are two elements 2 and 3 in
the list. But there is no element [2,3] in
the list.
Page 19 of 67
NMUISA Academic Affairs 2021/2022
65) Matplotlib can not recognize the 67) Please fill in the ( 1 ) to get the max
following formats to specify black value of BMI of every person :
import numpy as np
A.'b' height = [1.65, 1.6, 1.7, 1.76]
B.'black' weight = [62, 50, 65, 65]
C.(0,0,0) maxBMI = ( 1 )
D.'0'
Ans -
Ans - A max(np.array(weight)/(np.array(height)**
2))
66) Which one will plot the value of x=[1, 3,
2, 4] as the following:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(4)
A. height = np.array([1.65, 1.6, 1.7, 1.76])
import matplotlib.pyplot as plt weight = np.array([62, 50, 65, 65])
plt.plot(x) bmi = weight / (height ** 2)
plt.show() plt.xticks(x, ('Ankit', 'Hans', 'Joe', 'Flaco'))
B. plt.bar( 1 , color = "b")
import matplotlib.pyplot as plt
plt.line(x)
plt.show()
C.
import matplotlib.pyplot as plt
plt.pie(x)
plt.show()
D.
import matplotlib.pyplot as plt Ans - x, bmi
plt.bar(x)
plt.show()
Ans - A
Page 20 of 67
NMUISA Academic Affairs 2021/2022
69) Given the 72) Matplotlib graphs your data on Figures,
height = [1.65, 1.6, 1.7, 1.76] each of which can only contain one Axes.
weight = [62, 50, 65, 65] A. True
The BMI of every person can be B. False
calculated as the following:
bmi = height/(weight**2) Ans - B. False
Ans - B. False
Page 21 of 67
NMUISA Academic Affairs 2021/2022
77) Given numbers=[1,10,6,3] which is the 78) Please use the function open() to read the
value of each group of BMI. "BMI .txt" in the current folder, and extract
Plot a bar chart to show the number of each the information into a List, lst_info. Every
group of BMI as the following. item in the lst_A is the information of one
patient.
Please print and make sure that lst_info[0]
equals to
['135965', '1', '167.5', '73.8', '126','81']
The format of content in "BMI .txt" is
shown as the following :
Page 22 of 67
NMUISA Academic Affairs 2021/2022
79) Please use pandas to read the "BMI.txt" in 80) Given 10 patients' info are saved in a list
the current folder, and extract the information lst_a. Every item in the list is in the format
into a NumPy array, arr_A. Every item in the like ['135965', '1', '167.5', '73.8'], where
arr_A is the information of one patient. '135965' is the id, "1" is the gender. 167.5" is
Please add a new column of the BMI of the height, "73.8" is the weight. Please print
every patient and print the updated data the max value of the BMI and the id of the
frame. patient.
The "BMI.txt" is as the following:
lst_a=
[['135965', '1', '167.5', '73.8', '126', '81'],
['812772', '1', '170', '61', '138', '92'], ['737604',
'0', '157.5', '58.8', '144', '81'], ['822852', '0',
'155', '56.6', '109', '95'], ['494345', '1', '170',
'66.3', '113', '77'], ['283637', '1', '172.5', '81.3',
'122', '73'], ['807595', '1', '163', '65.2', '152',
'96'], ['123777', '1', '162', '55.6', '163', '93']]
Ans -
Ans -
import pandas as pd
max_bmi=0
df = pd.read_csv("BMI.txt",sep='\t')
index=0
df["BMI"]=round(df.weight/((df.height
for i in range(len(lst_a)):
/100)**2),2)
item = lst_a[i]
print(df)
h= float(item[2])/100
w= float(item[3])
bmi= w/(h**2)
if bmi>max_bmi:
max_bmi=bmi
index=i
print(index,max_bmi)
Page 23 of 67
NMUISA Academic Affairs 2021/2022
81) Write what it prints out after the below 84) Which definition of string is not correct?
code being executed. A.s1="Hello World!'
lst_a= [1,2,3,4,5] B.s1="Hello World!"
while len(lst_a)> 0: C.s1='Hello World!'
print (lst_a.pop(), end = ', ') D.s1="""Hello World!"""
A.5, 4, 3, 2, 1, Ans - A
B.5, 4, 3, 2, 1
C.5, 85) Given a variable S="Hello Python", which
D.5 expression can get the character 'o' in the
variable S?
Ans - A
A.S[2]
82) Write what it prints out after the below B.S[4]
code being executed. C.S[3]
D.S[-9]
lst_a = [x for x in range(3)]
for ix in lst_a : Ans - B
print (ix, end = ' ')
86) Giving lst=list(range(4)); b=["123"];
A.0 1 2 lst=a+b, which of the expressions is False
B.1 __________?
C.0
D.1 2 A."123" in lst
B."1" in lst
Ans - A C.1 in lst
D.[1,2] not in lst
83) Giving lst= list(range(10)), a=[1,2,3], the
value of the expression "a in lst" is ______. Ans - B
A.0
B.1
C.True
D.False
Ans - D
Page 24 of 67
NMUISA Academic Affairs 2021/2022
87) Given a variable S="Hello, 90) Which statement of the choices is
Python!" ,Write an expression to print the correct?_________.
middle character ""P"".
A.Lists are immutable, their values can
A.S(len(S)/2) not be changed
B.S[len(S)/2] B.The elements of a list must be of the
C.S[len(S)//2] same type.
D.S[len(S)*0.5] C.The item of a list can be a list.
D.lists are designated with [ ], with
Ans - C elements separated by colon.
Page 25 of 67
NMUISA Academic Affairs 2021/2022
93) For a list of lst=list(range(1,20,2)), which 96) Given str_01="Hello World", What is the
statement is not correct? value of len(str_01*3)
A.len(lst) = = 10 A.33
B.max(lst)= = 20 B.11
C.min(lst)= =1 C.30
D.lst[len(lst)//2] = = 11 D.10
Ans - A
Ans - B
97) Given str_01="Hello+World!", what is the
94) Given line = 'I like program'; etc = value of print(str_01[0:5])?
line.split(), what is the value of etc[1]? A.Hello
A.a blank space B.Hell
B.like C.Hello+
C."l" D.hello+
D."Program"
Ans - A
Ans - B
98) Given str_01="Hello World", What is the
95) Given line = 'From value of len(str_01*3)
[email protected] Sat Jan 5 A.33
09:14:16 2008', which of the expression is B.11
False? C.30
A.line.startswith('From ') D.10
B.len(line.split())==7
C.len(line.split("@"))==3 Ans – A
D.line.split()[-1]=='2008'
99) Given str_01="Hello+World!", what is the
Ans - C value of print(str_01[0:5])?
A.Hello
B.Hell
C.Hello+
D.hello+
Ans - A
Page 26 of 67
NMUISA Academic Affairs 2021/2022
100) Which line of code can realize the 102) The function of the following codes is :
following requirements. open the test.TXT file, use the variable f to
There is a test. txt file, open this file in append receive the return value and close the file.
mode, and use variable f to receive the return Plese fill in the line (1) to complete the above
value of the file function
A.f = open("test.txt", "r") f = ( line (1) )
B.f = open("test.txt", "w") content = f.read()
C.f = open("test.txt", "a") f.close
D.f = open("test.txt", "r+")
A.open("test.txt", "r")
Ans - C B.file("test.txt").open
C.read("test.txt", "r")
101) The function of the following codes is : D.fileopen("test.txt", "r")
open the test. TXT file, use the variable f to Ans - A
receive the return value and close the file.
Plese fill in the line (1) to complete the above 103) Which codes can not write "Wow, so
function beautiful!" in the test.txt file?
f = open("test.txt", "r") A.
content = f.read() f = open("test.txt", mode="w")
( line (1) ) f.write("wow,so beautiful!")
f.close()
A.f.close() B.
B.f.shutoff() f = open("test.txt", mode="r")
C.content.close() f.write("wow,so beautiful!")
D.content. shutoff() f.close()
C.
Ans - A = "wow,so beautiful!"
f = open("test.txt", mode="w")
f.write(str1)
f.close()
D.
f = open("test.txt", mode="a")
f.write("wow,so beautiful!")
f.close()
Ans - B
Page 27 of 67
NMUISA Academic Affairs 2021/2022
105) Given str_01="PYTHON", What is the
104) What do you need to do before using the value of len(str_01*3)
rename() function in Python programs?
Ans - 18
A.import os
B.import file 106) Given str_01="Hello, python!", the value
C.import rename of len(str_01*3) is 40.
D.import sys
A. True
Ans - A B. False
Ans - B. False
Page 28 of 67
NMUISA Academic Affairs 2021/2022