13. What will be the output of the following Python code snippet:
a={1:”A”,2:”B”,3:”C”}
for I j in a.items()
print(i,j,end=””)
a) A) ABC
b) 1:”A” 2:”B” 3:”C”
c) 123
d) A comment
Answer: .A comment
14. What will be the value of the following Python?
4+2**5//10
a) 3
b) 7
c) 77
d) 0
Answer: ..(A) 3
15. What does the np.arrange(5, 15, 2)function in NumPy do?
a) Creates an array with values from 5 to 15
b) Creates an array with values from 5 to 14 with a step of 2
c) Creates an array with values from 5 to 15 with a step of 2
d) Creates an array with values from 5 to 14
Answer:(C) A line that is indented less than the previous line
16. Considering that you have imported numpy as np, Which of the following is the output displayed by the Python instruction, print(np.array([[3], [4], [5], [6]], shape)
a) 1, 4)
b) (3, 6)
c) (3, 4, 5, 6)
d) (4, 1)
Answer: .(A) (1, 4)
17. What will be the output of the following Python code snippet
test = {1: ‘A’, 2: ‘B’, 3:’C’}
del test[1]
test[1] = ‘D’
del test[2]
print(len(test))
a) 2
b) 0
c) 1
d) Error as the key-value pair of 1: ‘A’ is already deleted
Answer: .(A) 2
18. What will be the output of print(0xa + 0xB + 0xC):
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
Answer: .(D) 33
19. What is the output of the following assignment operator?
a = 10
b = a = 2
print(b)
a) 10
b) 8
c) SyntaxError
d) No error but no output too
Answer: .(B) 8
20. What is the time complexity of a basic algorithm for finding the largest number in an array with n elements?
a) O(n)
b) O(log n)
c) O(n^2)
d) O(1)
Answer: .(A) O(n)
21. What will be the output of the following Python code?
for i in range(float(‘inf’)):
print(i)
a) 0.0.0.1 0.2 0.3 …
b) 0.0 1.0 2.0 3.0 …
c) 0 1 2 3
d) none of the mentioned
Answer: .(D) none of the mentioned
22. What will be the output of the following Python code?
l=[1, 0, 2, 0, ‘hello’,”,
list(filter(bool, l))
a) [1, 0, 2, ‘hello’,”,]
b) [1, 2, ‘hello’]
c) Error
d) [1,0,2,0, ‘hello’,”,]
Answer: .(B) [1, 2, ‘hello’]
23. A Python module is a file with the______file extension that contains valid Python code.
a) .py
b) .module
c) .pymodule
d) .pym
Answer: .(A) .py
24. 134 Which of the following is incorrect?
a) (A) x = 0b101
b) (B) x = 0x4f5
c) (C) x = 19023
d) (D) x = 03968
Answer: .(D) x = 03968
25. Consider the following code:
x = 6
y = 3
print(x// y, x % y)
What is the output?
a) 20
b) 21
c) 23
d) 31
Answer: .(A) 20
26.Which programming paradigm focuses on breaking down a program into smaller, reusable parts called function or procedures?
a) Procedural programming
b) Object-oriented programming
c) Functional programming
d) Imperative programming
Answer: .(A) Procedural programming
27.What will be the result of the following Python code?
a = {1, 2, 3}
b = {3, 4, 5}
print(a & b)
a) {1, 2, 3 4, 5}
b) {3}
c) {1, 2}
d) {1, 2, 4, 5}
Answer: .(B) {3}
28. What will the following code output?
s = “hello world”
print(s[:5] + s[6:])
a) hello world
b) helloWorld
c) helloworld
d) error
Answer: .(C) helloworld
29. The output of the following code
if x=56.236?
Print(“%.2f”%x)
a) 56.23
b) 56.2355
c) 56
d) 56.24
Answer: ..(D) 56.24
30. How many arguments a Python program can accept from the command line.
a) One
b) Two
c) Three
d) Any
Answer:(D) Any
31. what is the purpose of the__ all__ variable in a Python module?
a) It define what variables have to be imported to another file
b) It defines all functions and classes in the module
c) It is a reserved keyword for module exports
d) It indicates the module’s version number
Answer: .(A) It define what variables have to be imported to another file
32. How do you reverse a NumPy array through slicing?
a) To search for elements in an array
b) To locate the position of elements in an array
c) To replace elements in an array with a specified value
d) To create a new array with specified elements
Answer: .(A) To search for elements in an array
33. Using NumPy, a developer can perform which of the following operators?
a) Mathematical and logical operations on arrays
b) Fourier transforms and routines for shape manipulation
c) Operations related to linear algebra
d) All of the above
Answer: .(D) All of the above
34.What will be the output of the following Python code?
f=lambda x bool(x%2)
print(f(20), f(21))”
a) True False
b) True False
c) False True
d) False True
Answer:(D) False True
35.What will be the output of the following Python code?
def f1(a,b=[]):
b.append(a)
return b
print(f1(2,[3,4]))
a) [3,2,4]
b) [2,3,4]
c) [3,4,2]
d) [3,4,2]
Answer: .(C) [3,4,2]
36.You have been given an array, ARR (having N elements) and an element X. Consider the two algorithms as follows:
Algo 1 and AIgo 2.
The Algo 1 finds whether X is present in ARR or not.
Algo 2 identifies the count of occurences of x in ARR. In context of AI
a) Count of retrieved elements from ARR in both algorithms will always same
b) Count of retrieved elements from ARR in both algorithms will always different
c) Count of retrieved elements from ARR in both algorithms will sometime same and sometime different
d) None of the above
Answer: .(A) Count of retrieved elements from ARR in both algorithms will always same
37. You have been given an array, ARR (having N elements) and an element X. Consider the two algorithms as follows:
Algo 1 and AIgo 2. The Algo 1 finds whether X is present in ARR or not.
Algo 2 identifies the count of occurences of x in ARR. In context of AI
a) Count of retrieved elements from ARR in both algorithms will always same
b) Count of retrieved elements from ARR in both algorithms will always different
c) Count of retrieved elements from ARR in both algorithms will sometime same and sometime different
d) None of the above
Answer: ..(A) Count of retrieved elements from ARR in both algorithms will always same
39. What does Python scope determine?
a) Where a name is visible in program
b) How many times function will be called
c) When while or for loop will end
d) What the LEGB rule means
Answer: .(A) Where a name is visible in program
40.What will be the output of the following Python ?
def func(x):
global y
return x + y
y = 5
print(func(3))
print(y)
a) 15 10
b) 8 10
c) 8 5
d) 15 5
Answer: .(C) 8 5
41. What is a namespace in the Python?
a) A collection of related functions and variables
b) A data type in Python
c) A type of object in Python
d) A way of organizing names that prevents naming conflicts
Answer: .(D) A way of organizing names that prevents naming conflicts
42. Identify the function create an array with evenly spaced values between two numbers.
a) np.linspace()
b) np.arange()
c) np.arange_space()
d) np.range().
Answer: .(A) np.linspace()
43. Which of the following methods is used to add an element to the end of a list in Python?
a) add()
b) append()
c) extend()
d) insert()
Answer: .(B) append()
44.What will be the output of the following Python program?
z=set(‘abc’)
z add(‘san’)
z.update(set([‘p’, ‘q’]))
z
a) {‘a’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b) {‘abc’, ‘p’, ‘q’, ‘san’}
c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d) {‘a’, ‘b’, ‘c’,[‘p’, ‘q’], ‘san’}
Answer: .(C) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
45.Which of the following is an example of a sequence data type in Python?
a) Dictionary
b) Set
c) Tuple
d) Class
Answer: ..(C) Tuple
46.If a dimension is given as ________ in a reshaping operation, the other dimensions are automatically calculated.
a) 0
b) 1
c) Negative one
d) Infinite
Answer: .(C) Negative one
47.Let us assume 4 is 100 in binary and 11 is 1011.What is operators?
a = 4
b = 11
print(a | b)
print(a>>2)
a)(A) 15
1
b)(B) 14
1
c) (C) 12
2
d)(D) 16
2
Answer: ..(A) 15
1
48. What will be the output of the following Python code?
>>>t1 = (1,2,4,3)
>>>t2 = (1,2,3,4,)
>>>t1 < t2
a) true
b) false
c) true
d) false
Answer:(D) False
49. What will be the output of the following Python code?
nums = set([1,1,2,3,3,4,4])
print(len(nums))
a) 7
b) Error, invalid syntax
c) 4
d) 8
Answer:.(C) 4
50.What will the following recursive function return when factorial(3)?
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
print(factorial(3))
a) 3
b) 9
c) 6
d) 1
Answer:.(C) 6
51.What is the use of truncate() method in file?
a) Resizes the file to the given number of bytes
b) the file to the given number of bytes
c) Deletes the file size
d) None of the mentioned
Answer: ..(A) Resizes the file to the given number of bytes
52.What signifies the end of a statement block or suite in Python?
a) {}
b) Comment
c) A line that is indented less than the previous line
d) A comment
Answer: .(C) A line that is indented less than the previous line
53.Point out the incorrect statement:
a) Both Series and ndarrays can be passed as argument to NumPy functions
b) The major difference between Series and ndarrays is that the data is arranged based on label in Series, When Series is operated on
c) A DataFrame is similar to a fixed-size dict because you can use the index lables to get and set values
d) A DataFrame is similar to a fixed-size dict because you can use the index lables to get and set values
Answer: ..(C) A DataFrame is similar to a fixed-size dict because you can use the index lables to get and set values
54.What will be the output of the following Python code?
a) (A) Hello
WorldWorldWorldWorldWorld
b) (B) Hello
World 5
c) (C) Hello
World World World World World
d) (D) Hello
HelloHelloHelloHelloHello
Answer: ..(A) Hello WorldWorldWorldWorldWorld
55.Write a list for statement for each number and its cube 1=[1,2,3,4,5,6,7,8,9].
a) [x**3 for x in 1]
b) [x**3 in 1]
c) [x^3 in 1]
d) [x**3 for x3 in 1]
Answer: ..(A) [x**3 for x in 1]
56.What will be the output for the following code:
Import numpy as np
a = np.array([1,2,3])
print a
a) [1,2,3]
b) [[1,2,3]]
c) [1]
d) Error
Answer: ..(B) [[1,2,3]]
57.If a is 5 and b is 6, which of the following is the output displayed by the instruction,
Print(a & b) in Python?
a) 4
b) 5
c) 6
d) 11
Answer: ..(A) 4
58.How many keyword arguments can be passed, to a function in a single function call?
a) Zero
b) One
c) Zero or more
d) One or more
Answer:.(C) Zero or more
59.Which of the following statement is false regarding functions?
a) A function definition begins with def keyword.
b) A function may or may not have parameters
c) A function may or may not have return statement
d) None
Answer: .(D) None
60.Define a parameter in a function?
a) A value passed to a function when calling it
b) A variable used inside a function
c) A keyword used to define a function
d) A reserved memory location
Answer: ..(A) A value passed to a function when calling it
61.Which of the following will delete key value pair for key=”tiger” in dictionary?
a) del dic[“tiger”]
b) dic[“tiger”].delete()
c) delete(dic,[“tiger”])
d) del(dic,[“tiger”])
Answer: ..(A) del dic[“tiger”]
62.Which module in Python can be used for working with PDF forms?
a) pdfrw
b) pdftk
c) PyPDF2
d) All of the above
Answer: .(D) All of the above
63.What is the result of the following NumPy expression:
np.arrange(10,20,2)
a) [10,12,14,16,18]
b) [10,11,12,13,14,14,16,17,18,19]
c) [0,2,4,6,8]
d) [2,4,6,8,10]
Answer: ..(A) [10,12,14,16,18]
64.What will be the output of the following code?
print(‘abzzef12’.replace(‘zz’,’12’))
a) ab12ef12
b) abzzef12
c) ab12efzz
d) none of them
Answer: .(A) ab12ef12
65.What is the output of the following code?
t = (1,2,3,4,5)
print(t[-2:])
a) (4,5)
b) (3,4)
c) (2,3)
d) IndexError
Answer:.(A) (4,5)
66.What type of data is: a=[(1,1),(2,4),(3,9)]?
a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type
Answer: ..(B) List of tuples
67.What will be the output of the following Python code?
str = input(“Enter your input:”);
print”Received input is:”,str
a) (A(A) Enter your input:[x*5 x in range(2,10,2)]
Received input is: [x*5 x in range(2,10,2)]
)
b) (B) Enter your input:[x*5 x in range(2,10,2)]
Received input is: [10, 30, 20, 40]
c)(C) Enter your input:[x*5 x in range(2,10,2)]
Received input is: [10, 10, 30, 40]
d) (D) None of the mentioned
Answer: ...(A) Enter your input:[x*5 x in range(2,10,2)]
Received input is: [x*5 x in range(2,10,2)]
68.In the context of programming documentation, which practice is most effective for maintaining code readability and usability?
a) Using comments only for complex algorithms and edge cases
b) Including detailed explanations for every line of code
c) Writing modular code with accompanying concise comment
d) Separating the documentation entirely from the source code
Answer: ..(C) Writing modular code with accompanying concise comment
69.Suppose list1 is [3,4,5,20,5], what is list1.index(5)?
a) 0
b) 1
c) 4
d) 2
Answer:(D) 2
70.Consider the following Python code
x = 30
def outer_function();
x = 10
def inner_function();
x = 20
result = sum([x, globals()[‘x’]])
print(result)
inner_function()
outer_function()
Based on the code above, what will be printed
a) 20
b) 30
c) 50
d) 60
Answer:(C) 50
71.Python dictionary is used to store the data in a___ format.?
a) Group value
b) Select value
c) No value
d) Key value
Answer:(D) Key value
72.What the following code does:
object.readline(10)
a) Read first 10 lines
b) Read first 10 characters of line
c) Read first 10 bits of line
d) Read first 10 words of line
Answer:(B) Read first 10 characters of line
73.What will be the output of the following Python code?
def writer():
title = ‘sir’
name = (lambda x:title + ‘ ‘ + X)
return name
who = writer()
who(‘Arthur’)
a) Arthur Sir
b) Arthur
c) Sir Arthur
d) None of these
Answer:(A) Arthur Sir
74.What is the method inside the class in Python language?
a) Object
b) Function
c) Attribute
d) Target
Answer:(B) Function
75.What will be the output of the following Python code?
a) Hello World! Hello World!
b) ‘Hello World!’ ‘Hello World!’
c) Hello Hello
d) (D) None of the mentioned
Answer:(A) Hello World! Hello World!
76.What will be the output of the following Python code? print (r“\nhello”)
a) A new line and hello
b) \nhello
c) The letter r and then hello
d) Error
Answer:(B) \nhello
77.What does the NumPy function np.zeros() do?(r“\nhello”)
a) Creates an array filled with zeros
b) Computes the square root of each element in an array
c) Calculates the cumulative sum of an array
d) Rounds each element of an array to the nearest integer
Answer:.(A) Creates an array filled with zeros
78.What will be output for the following code?
Import numpy as np
a = np.array([1,2,3,5,8])
print(a.ndim)
(r“\nhello”)
a) 0
b) 1
c) 2
d) 3
Answer:.(B) 1
79.What will be the output of the following Python code snippet ?
a = [0, 1, 2, 3]
for a[-1] in a
print(a[-1]
(r“\nhello”)
a) 0 1 2 3
b) 0 1 2 2
c) 3 3 3 3
d) Error
Answer:.(B) 0 1 2 2
80.Which of the following is NOT a step in the problem-solving process using algorithms?
a) Analyzing the problem
b) Writing code in a programming language
c) Developing a solution using algorithms
d) Testing and debugging the program
Answer:.(B) Writing code in a programming language
81.What type of array is generally generated in computer arguments?
a) 1-D array
b) 2-D array
c) 2-D array
d) Jagged array
Answer:.(A) 1-D array
82.What is datatype of below NumPy Array: np.array([2,2]).dtype,
np.array([2,’2’]).dtype,
np.array([2,2.0]).dtype
a) int,int,int
b) int,float,string
c) int, string, float
d) string,string,string
Answer:.(C) int, string, float
83.Which of the following assigns input to a variable?)
a) INPUT = thisVar
b) thisVar <-INPUT>
c) INPUT <-thisVar>
d) All of these
Answer:.(A) INPUT = thisVar
84.What will be the output of the following python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
a) Error, there is more than one return statement in a single try –finally bio
b) 3
c) 2
d) 1
Answer:.(C) 2
84.What will be the output of following code?
a = True
b = false
c = false
result = a or b and c print(result)
a) TRUE
b) False
c) None
d) Error
Answer:.(A) TRUE
85.Which of the following is correct method to delete any file in Python?
a) os.remove(‘file_path’)
b) os.link(‘file_path’)
c) os.rmfile(‘file_path’)
d) pathlib.Path(‘file_path’).remove()
Answer:.(A) os.remove(‘file_path’)
86.Which function overloads the >> operator?
a) __more__()
b) __gt__()
c) __ge__()
d) None of the mentioned
Answer:.(D) None of the mentioned
87.What will be the output of the following Python code? print (r“\nhello”)
a) A new line and hello
b) \nhello
c) The letter r and then hello
d) Error
Answer:(B) \nhello
88.What does the NumPy function np.zeros() do?
a) Creates an array filled with zeros
b) Computes the square root of each element in an array
c) Calculates the cumulative sum of an array
d) Rounds each element of an array to the nearest integer
Answer:.(A) Creates an array filled with zeros
89.What will be output for the following code?
Import numpy as np
a = np.array([1,2,3,5,8])
print(a.ndim)
a) 0
b) 1
c) 1
d) 3
Answer:.(B) 1
90.What will be the output of the following Python code snippet ?
a = [0, 1, 2, 3]
for a[-1] in a
print(a[-1]
a) 0 1 2 3
b) 0 1 2 2
c) 0 1 2 3
d) Error
Answer:.(B) 0 1 2 2
.91.Which of the following is NOT a step in the problem-solving process using algorithms?
a) Analyzing the problem
b) Writing code in a programming language
c) Developing a solution using algorithms
d) Testing and debugging the program
Answer:.(B) Writing code in a programming language
92.What type of array is generally generated in computer arguments?
a) 1-D array
b) 2-D array
c) 2-D array
d) Jagged array
Answer:.(A) 1-D array
93.What will be the output of the following code in Python?
print(“abc.DEF”.capitalize())
a) Abc.def
b) abc.def
c) abc.def
d) ABC.DEF
Answer:.(A) Abc.def
94.What will be the output of the following code in Python?
If a=(1,2,3,4) ; print(a[1 : -1]) is______
a) [2,3]
b) (2,3)
c) (2,3,4)
d) Error
Answer:.(B) (2,3)
95.What is the purpose of the “pass’ statement in a function definition?
a) It indicates the end of the function.
b) It is used to return a value from the function.
c) It is a placeholder for future code implementation.
d) It is a keyword for defining function parameters.
Answer:.(C) It is a placeholder for future code implementation.
96How do you check if a file/directory element in Python?
a) exists(file_name)
b) os.exists(file_name)
c) os.path.exists(file_name/dir_name)
d) file_exists(file_name)
Answer:.(C) os.path.exists(file_name/dir_name)
97Which statement is correct to import all modules from the package?
a) From package import all
b) From package import *
c) From package include all
d) From package include all
Answer:(C) From package include all
98.Which of the following is not correct function definition?
a) def fn(var1, var2)
b) def fn(var1, var2=5)
c) def fn(*var1, var2)
d) def fn(var1,)
Answer:.(C) def fn(*var1, var2)
99.Which of the following algorithm produces fiber.
a)Procedure Fibonacci(n) if n <= 1
Return n
else:
f() : = 0
f1 : = 1
i := 2
while i <= n:
temp : = f() + f1
f() := f1
f1 := temp
i := i + 1
return f1 End Fibonacci(n)
b)Procedure Fibonacci(n)
if n <= 1:
return n
else:
return Fibonacci(n - 1) + Fibonacci(n - 2)
End Fibonacci
c) Both A & B
d) None
Answer:.(a) a
100.Which data structure in Python is used to store 20 ordered collection of elements?
0 Comments