Explanation: The nonlocal keyword allows inner() to modify x from outer(), changing it to 10.
Question 13: Which of the following option is the correct statement to read and display the first 10 character of a text file "doc.txt"
A) F=open('doc.txt'); print(F.load(10))✗
B) F=open('doc.txt'); print(F.dump(10))✗
C) F=open('doc.txt'); print(F.read(10))✓
D) F=open('doc.txt'); print(F.write(10))✗
Explanation: The read(10) method reads the first 10 characters from the file.
Question 14: Let us import the numpy in your program as follows: from numpy import random as np. Which of the following can be the probable output for the instruction, print(np.randint(100))
A) 56✓
B) 156✗
C) 256✗
D) 356✗
Explanation: randint(100) generates random integers from 0 to 99.
Question 15: What will be the output of following instructions: print(np.array([[1,2,3],[4,5,6]]).shape)
A) (1,2)✗
B) (1,2,3)✗
C) (2,3)✓
D) (4,5)✗
Explanation: The array has 2 rows and 3 columns, so shape is (2,3).
Question 16: Given the following code, what will be the output?
import numpy as np
arr=np.array([1,2,3,4,5,6,7,8,9])
print(arr[::3])
A) [1,4,7]✓
B) [1,2,3]✗
C) [1,2,3,4,5]✗
D) [1,3,5,7,9]✗
Explanation: [::3] selects every 3rd element starting from index 0.
Question 17: What is the significance of "continue" statement in a for loop?
A) To exit the loop✗
B) To skip the remaining code and move to the next iteration✓
C) To restart the loop from the beginning✗
D) To print the current iteration and continue✗
Explanation: continue skips the current iteration and moves to the next one.
Question 18: What is the output of the following code? print(bool(0), bool(2.15), bool(-5), bool(2.0+1j))
A) True True False True✗
B) True False False True✗
C) False True False True✗
D) False True True True✓
Explanation: 0 is False, all other numbers (including complex) are True.
Question 19: What will be the output of the following Python Code?
a = {1:"A",2:"B",3:"C"}
b = {4:"D",5:"E"}
a.update(b)
print(a)
A) {1:'B', 2:'B', 3:'C'}✗
B) Method update() doesn't exist for dictionaries✗
C) {1:'B', 2:'B', 3:'C', 4:'D', 5:'E'}✗
D) {1:'A', 2:'B', 3:'C', 4:'D', 5:'E'}✓
Explanation: update() merges dictionary b into a, preserving original values.
Question 20: Kite box in a flow chart is used for _________
A) Connector✗
B) Decision✓
C) Statement✗
D) All of the above✗
Explanation: The diamond (kite) shape represents decision points in flowcharts.
Question 21: Execution of the following python statement will result in open("filename.txt", "w").write("Great Day\n")
A) Error✗
B) File not closed✓
C) Writing of file is not performed✗
D) None of the above✗
Explanation: The file will be written but not properly closed, which could cause issues.
Question 22: What will the following code print? x = [0,1,2,3,4,5] print(x[1:5:2])
A) [1,2,3,4]✗
B) [1,3]✓
C) [2,4]✗
D) Error✗
Explanation: The slice [1:5:2] means start at index 1, end before 5, step by 2.
Question 23: What is the advantage of Flow chart?
A) Systematic testing✓
B) Asystematic testing✗
C) Symmetric testing✗
D) Improper Communication✗
Explanation: Flow charts help in systematic testing and understanding of program flow.
Question 24: What will be the output of the following Python code?
L1 = [2, 4, 6]
L2 = [-2, -4, -6]
for i in zip(L1, L2):
print(i)
A) 2 -2 4, -4 6, -6✗
B) [(2,-2), (4,-4), (6,-6)]✗
C) (2, -2) (4, -4) (6, -6)✓
D) [-4, -16, -36]✗
Explanation: zip() pairs elements from both lists and returns tuples.
Question 25: What is the result of the following code?
Explanation: Boolean indexing returns elements where condition (arr > 30) is True.
Question 40: If A = 0 then GCD(A,B) is __________
A) A✗
B) B✓
C) A*A✗
D) 1✗
Explanation: GCD of 0 and B is B, as every number divides 0.
Question 41: What will be the output of the following Python code?
string="my name is x"
for i in string.split():
print(i, end=",")
A) m,y, ,n,a,m,e, ,i,s, ,x,✗
B) my,name,is,x,✓
C) m,y, ,n,a,m,e, ,i,s, ,x✗
D) error✗
Explanation: split() breaks at whitespace and prints words separated by commas.
Question 42: What is the output of the following code?
import numpy as np
a=np.array([1,2,3])
b=np.array([4,5,6])
c=np.stack((a,b))
print(c)
A) [[1,2,3],[4,5,6]]✓
B) [[1,4],[2,5],[3,6]]✗
C) [1,2,3,4,5,6]✗
D) Error✗
Explanation: stack() joins arrays along a new axis by default.
Question 43: What will be the following output of the following statement: print(3.2**2**3+99/11)
A) 244✗
B) 244.0✓
C) -244.0✗
D) Error✗
Explanation: 2**3=8 → 3.2^8=1099.51 → 99/11=9 → 1099.51+9=1108.51 (Note: Actual calculation differs from options)
Question 44: Consider the following syntax for file open function Filehandler=open("filename","open mode","buffering") which of the following statement is False?
A) No buffering will be used if 0 is passed as buffering integer✗
B) 0 as buffering integer is allowed only in text mode✓
C) 0 as buffering integer is allowed only in binary mode✗
D) Positive integer as buffering integer implies full buffering✗
Explanation: 0 buffering is only allowed in binary mode, not text mode.
Question 45: What is the result of the following code?
st=[1,2,3,4,5]
st[1:4]=[6,7,8]
print(lst)
A) [1,6,7,8,5]✗
B) [1,6,7,8]✗
C) [6,7,8,4,5]✗
D) NameError✓
Explanation: Variable 'lst' is not defined (should be 'st').
Question 46: What will be the output of the following Python code?
#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)
A) [2,4,6]✗
B) [1,4,9]✗
C) [2,4,6][1,4,9]✗
D) There is a name clash✓
Explanation: The second import overwrites the first change() function.
Question 47: What will be the output of the following Python function? min(max(False,-3,-4),2,7)
A) -4✗
B) -3✗
C) 2✗
D) False✓
Explanation: False equals 0 in comparisons, max(0,-3,-4)=0, then min(0,2,7)=0 (False).
Question 48: What will be the following code output?
import numpy as np
arr=np.array([10,20,30,40,50])
print(arr[arr>30])
A) [30,40,50]✗
B) [10,20]✗
C) [40,50]✓
D) Error: Invalid comparison✗
Explanation: Boolean indexing returns elements where condition is True.
Question 49: Which of the following is the output of the instruction, print(math.log(64,2))
A) 6.0✓
B) 7.0✗
C) 2.0✗
D) 64.0✗
Explanation: log(64,2) calculates log base 2 of 64, which is 6.
Question 50: Which of the following functions can delete an element from a list, if it's value is given?
A) pop()✗
B) remove()✓
C) del()✗
D) all of these✗
Explanation: remove() deletes by value, pop() by index, del by index/slice.
Question 51: Observe the following code and identify what will be the outcome?
import numpy as np
a=np.array([10,20,30,40])
b=np.array([18,15,14])
c=np.array([25,24,26,28,23])
x,y,z=np.ix_(a,b,c)
print(x)
A) [[[10]] [[20]] [[30]] [[40]]]✓
B) [[[1]] [[2]] [[3]] [[4]] [[5]]]✗
C) Both a and b✗
D) Error✗
Explanation: ix_() creates a mesh grid, printing x shows array elements in 3D structure.
Question 52: What does the following code print to the console? >>if 88>100:print("cardio")
A) 88✗
B) cardio✗
C) 100✗
D) Nothing is printed✓
Explanation: Condition 88>100 is False, so print() isn't executed.
Question 53: Istrip() method is used for
A) Delete all the leading characters✗
B) Delete all the trailing characters✗
C) Delete all the leading and trailing characters✓
D) Delete uppercase characters✗
Explanation: strip() removes both leading and trailing whitespace.
Question 54: What will be the output of following Python expression if x=56.236? print("%.2f"%x)
A) 56.236✗
B) 56.23✗
C) 56✗
D) 56.24✓
Explanation: %.2f formats to 2 decimal places with rounding.
Question 55: Which of the following is NOT a sequence data type in Python?
A) String✗
B) List✗
C) Dictionary✓
D) Tuple✗
Explanation: Dictionaries are mapping types, not sequence types.
Question 56: Recursive function is ___________________.
A) A function that calls itself✓
B) A function that calls other functions✗
C) Both✗
D) None of the above✗
Explanation: Recursion means a function calls itself.
Question 57: Documentation in software development is important because it__________________.
A) Helps in maintaining the program in the long term✓
B) Is required by law for all software projects✗
C) Ensures the program's compatibility with different platforms✗
D) Replaces the need for testing and debugging✗
Explanation: Documentation aids long-term maintenance and understanding.
Question 58: What is the result of the following Python expression 5//3**2?
A) 0✓
B) 1✗
C) 4✗
D) Error message✗
Explanation: ** has higher precedence: 3**2=9 → 5//9=0.
Question 59: What is the output of the following code?
import numpy as np
a=np.array([[1,2],[3,4]])
print(a.ndim)
A) 0✗
B) 1✗
C) 2✓
D) 3✗
Explanation: ndim returns number of dimensions (2 for 2D array).
Question 60: Which function is used to return the current file position in bytes?
A) tell()✓
B) seek()✗
C) read()✗
D) write()✗
Explanation: tell() returns current position of file pointer.
Question 61: What is the value returned by math.floor(3.4)?
A) 3✓
B) 4✗
C) 3.0✗
D) 4.0✗
Explanation: floor() returns the largest integer ≤ input (3.4 → 3).
Question 62: Which operator is used for slicing an ndarray?
A) ,✗
B) :✓
C) ;✗
D) /✗
Explanation: Colon (:) is used for slicing arrays and lists.
Question 63: Which of the following statement display "ARM" two times?
A) >>>"ARM" ++2✗
B) >>>"ARM" +2✗
C) >>>"ARM" *2✓
D) >>>"ARM" **2✗
Explanation: String multiplication repeats the string ("ARM"*2 = "ARMARM").
Question 64: Algorithm cannot be represented by ________________.
A) pseudo codes✗
B) syntax✓
C) flowcharts✗
D) programs✗
Explanation: Syntax is language rules, not an algorithm representation method.
Question 65: What is NumPy?
A) A programming language✗
B) A library for numerical computing in Python✓
C) A data visualization tool✗
D) A file format for storing data✗
Explanation: NumPy is Python's fundamental package for numerical computing.
Question 66: Which of the following is true about function argument in Python?
A) All arguments must have default values✗
B) Only keyword arguments can be used✗
C) Only one argument is allowed in a function✗
D) Arguments are optional can be omitted✓
Explanation: Python functions can be defined with optional arguments.
Question 67: What is the purpose of the for loop in Python?
A) To define a function✗
B) To perform conditional execution✗
C) To iterate over a sequence of items✓
D) To execute a block of code when a condition is true✗
Explanation: for loops iterate over sequences (lists, strings, etc.).
Question 68: Which of the following is true about the import statement in Python?
A) It can only import one module at a time✗
B) It can import multiple modules at a time✓
C) It can import modules from any directory✗
D) It can import modules from any programming language✗
Explanation: Multiple imports can be done with comma separation.
Question 69: How do you define a function in Python?
A) def function_name():✓
B) function function_name():✗
C) define function_name():✗
D) def(): function_name✗
Explanation: Python uses 'def' keyword for function definition.
Question 70: What does the seek() function do in Python?
A) Reads a specified number of characters from a file✗
B) Moves the file pointer to a specific position✓
C) Writes a line of text to a file✗
D) Closes a file✗
Explanation: seek() changes the file's current position.
Question 71: ____________ creates an inferior process that runs your program.
A) Run✗
B) Exit✗
C) Execute✗
D) E✓
Explanation: (Note: This question seems incomplete/ambiguous)
Question 72: What will be the output of the following Python code snippet?
x='abcd'
for i in range(len(x)):
i.upper()
print(x)
A) a b c d✗
B) 0 1 2 3✗
C) error✗
D) none of the mentioned✓
Explanation: i.upper() does nothing to string x, original x is printed.
Question 73: _________ refers to the ability to make decisions based on criteria conditions.
A) Sequence✗
B) Selection✓
C) Iteration✗
D) None of these✗
Explanation: Selection structures make decisions (if/else).
Question 74: Which of the following exceptions is raised if the file already exists when opening it in 'x' mode?
A) FileError✗
B) IOError✗
C) FileExistsError✓
D) None of these✗
Explanation :
Question 75: What is the purpose of the seek() method in Python file handling?
A) To move the file cursor to a specific position✓
B) To read the entire contents of a file✗
C) To write data to a file✗
D) To close a file✗
Explanation: seek() positions the file pointer at specified byte position.
Question 76: Which of the following is the truncation division operator in Python?