M3-R5: Programming and Problem Solving Through Python Language
Set-01
Q1. Which is the following number can never be generated by the following code:
random.randrange(0,50)
A. 0
B. 1
C. 49
D. 50
Answer: 50
Q2. Python is a case sensitive language when dealing with identifiers.
A. True
B. False
C. Sometimes
D. Never
Answer: B
Q3.Which of the following is true for variable names?
A. Unlimited length
B. Limited length
C. Ampersand can be used in its name
D. None of the Above
Answer: A
Q4. The examination of changing values of variables is called stepping.
A. True
B. Flase
C. Can’t s say
D. May be
Answer: B (called Tracing)
Q5. What will be the output of the following?
Import numpy as np
Print(np.minimum([2,3,4],[1,5,2]))
A. [1 2 5]
B. [1 5 2]
C. [2 3 4]
D. [1 3 2]
Answer: D
Q6.What is the data type of following object?
A=[5,’abc’,3,2,6]
A. Tuple
B. Array
C. List
D. Dictionary
Answer: C
Q7. Flowcharts and algorithms are used for
A. Better programming
B. Efficient coding
C. Easy testing and debugging
D. All of the Above
Answer: D
Q8. Determine the output:
for i in range(20,30,10):
j=i/2
print(j)
A. 10 15
B. 10.0 15.0
C. 10.0
D. None of these
Answer: C
Q9. Method which uses a list of well defined instructions to complete a task starting from a given initial state to end state is called as----------
A. Program
B. Algorithm
C. Flowchart
D. Both A and C
Answer: B
Q10. -------- is a connector showing the relationship between the representative shapes.
A. Line
B. Arrow
C. Process
D. Box
Answer: B
Q11. ---------------------- scans the entire program and translates it as a whole into machine code.
A. Compiler
B. Interpreter
C. Debugger
D. None of Above
Answer: A
Q12.What is the output of below python code?
def say(message, times=1):
print(message*times)
say('Hello')
say('World',5)
A. Hello
WorldWorldWorldWorldWorld
B. Hello
World5
C. Hello
World,World,World,World,World
D. Hello
HelloHelloHelloHelloHello
Answer: A
Q13. The action performed by a -------structure must eventually cause the loop to terminate.
A. Sequence
B. Process
C. Repetition
D. Case
Answer: C
Q14. The output of following python code ---
a=true
b=false
c=false
if a or b and c:
print("HELLO")
else:
print ("hello")
A. HELLO
B. Hello
C. HellO
D. None of these
Answer: A
Q15. NumPy stands for
A. Numbering Python
B. Number in Python
C. Numerical Python
D. None of these
Answer: C
Q16. A flowchart that outlines the main segment of a program.
A. Queue
B. Macro
C. Micro
D. Union
Answer: B
Q17. Which statement will move file pointer 10 bytes backward from current position?
A. f.seek(-10,0)
B. f.seek(-10,1)
C. f.seek(10,0)
D. None of above
Answer: A
Q18. Choose the answer for statement 1
Import-----------------------# statement 1
Rect=[]
While True:
m=int(input(“Enter”))
nm=input(“Enter”)
Temp=[m,nm]
Rect.append(temp)
Ch=input(“Enter choice(Y?N”)
If ch.upper==”N”:
Break
F=open(stud.dat”,”--------------------------“) #statement 2
------------------------------.dump(rec,f) #statement 3
-----------------.close() #statement 4
A. csv
B. load
C. pickle
D. unpickle
Answer: C
Q19. Which of the following is the use of function in python?
A. Functions are reusable pieces of programs
B. Functions do not provide better modularity for your application
C. You cannot also create your own functions
D. All of mentions
Answer: A
Q20. What is the output of following code?
A=[[1,2,3],
[4,5,6],
[7,8,9]]
print(A[1][:])
A. [1,2,3]
B. [4,5,6]
C. [2,5,8]
D. None of these
Answer: B
Q21. What will be output for the following code?
import numpy as np
a=np.array([1,2,1,5,8])
b=np.array([0,1,5,4,2])
c=a+b
c=c*a
print(c[2])
A. 6
B. 10
C. 0
D. None of these
Answer: A
Q22. Actual instructions in flowcharts are represented in -----
A. Circles
B. Boxes
C. Arrows
D. Line
Answer: B
Q23.In Python, which of the following functions is a built-in function?
A. val()
B. print()
C. func_k()
D. None of these
Answer: B
Q24. Which mode creates a new line file if the file does not exist?
A. Write mode
B. Append mode
C. Both A & B
D. None of the these
Answer: C
Q25. What is the output of the following code?
import numpy as np
a=np.array([[1,2,3])
print(a.ndim)
A. 1
B. 2
C. 3
D. 0
Answer:B
Q26. Which of these definitions correctly describes a module?
A. Denoted by triple quotes for providing the specification of certain program elements
B. Design and implement of specific functionality to be incorporated into a program
C. Defines the specifications of how it is to be used
D. Any program that reuses code
Answer: D
Q27. What is the output of the following code?
a=15
b=6
print(a and b)
print(a or b)
A. True True
B. False False
C. 6 15
D. 15 6
Answer: C
Q28. ------------------------------ immediately terminates a loop entirely.
A. Break
B. Continue
C. Pass
D. None of these
Answer: A
Q29. Identity the correct function header.
A. def fun(a=2,b=3,c)
B. def fun(a=2,b,c=3)
C. def fun (a,b=2,c=3)
D. def fun(a,b,c=3,d)
Answer: C
Q30. In which language is Python written?
A. C
B. C++
C. Java
D. None of these
Answer: A
Q31. What is the output of the below program?
def func(a,b=5,c=10):
print('a is',a,'and b is',b,'and c is',c)
func(3,7)
func(25,c=24)
func(c=50,a=100)
A. a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50
B. a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24
a is 50 and b is 100 and c is 5
C. a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
a is 5 and b is 100 and c is 50
D. None of these
Answer: A
Q32. In computer science, algorithm refers to a pictorial representation of a flowchart.
A. True
B. False
C. Can’t say
D. May be
Answer: B
Q33.What will be the output of the following algorithm for a=5, b=8, c=6?
Step 1: Start
Step 2: Declare variable a, b and c.
Step 3: Read variable a, b and c.
Step 4:
if a>b
if a>c
Display a is the largest number.
Else
Display c is the largest number.
Else:
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: stop
A. B is the largest number
B. A is the largest number
C. C is the largest number
D. Stop
Answer: A
Q34. What is the output of the following code?
import numpy as np
a=np.array([1.1,2,3])
print(a.dtype)
A. int32
B. float64
C. float
D. None of these
Answer: B
Q35.Choose the answer for statement 4
Import-----------------------# statement 1
Rect=[]
While True:
m=int(input(“Enter”))
nm=input(“Enter”)
Temp=[m,nm]
Rect.append(temp)
Ch=input(“Enter choice(Y?N”)
If ch.upper==”N”:
Break
F=open(stud.dat”,”--------------------------“) #statement 2
------------------------------.dump(rec,f) #statement 3
-----------------.close() #statement 4
A. F
B. Rec
C. File
D. Stud
Answer: A
Q36. Which of the following is not the built in function?
A. Input()
B. Tuple()
C. Print()
D. Dictionary()
Answer: D
Q37. What will be the output of following code?
Import math
abs(math.sqrt(36))
A. Error
B. 6
C. -6
D. 6.0
Answer: D
Q38.What is the full form of CSV?
A. Comma Separation Value
B. Comma Separated Variable
C. Comma Separated Values
D. Common Syntax Value
Answer: C
Q39. What will be output for the following code?
import numpy as np
a=np.array([11,2,3])
print(a.min())
A. 2
B. 1
C. 11
D. 3
Answer: A
Q40. ----------------------- is part of user documentation.
A. Class Diagram
B. Code Comment
C. Use Case
D. Installation Guide
Answer: D
Q41. Which attribute is used to find the data type of numpy array?
A. type(array)
B. dtype
C. object.type(array)
D. numpy(type)
Answer: B
Q42. Which statement will return one line from a file (file object is ‘f’)?
A. f.readlines()
B. f.readline()
C. f.read()
D. f.line()
Answer:B
Q43. Which of the following is not a keyword in python?
A. return
B. in
C. False
D. false
Answer: C
Q44. What will be the output of the following Python code?
def C2F(c):
return c*9/5+32
print(C2F(100))
print(C2F(0))
A. 212.0
32.0
B. 314
24
C. 567
98
D. None of the Above
Answer: A
Q45.What is the output, it user has entered 55?
A. int
B. float
C. double
D. str
Answer: D
Q46. Which of the following statement will execute in last?
def s(n1): #Statement 1
print(n1) #Statement 2
n2=4 #Statement 3
s(n2) #Statement4
A. Statement 1
B. Statement 2
C. Statement 3
D. Statement 4
Answer: C
Q47. How to copy one list to another in Python?
A. a1=list(a2)
B. a1=a2.copy()
C. a1[]=a2[:]
D. All of these
Answer: B
Q48. Suppose a tuple arr contains 10 elements. How can you set 5th element of the tuple to ‘Hello’?
A. arr[4]=’Hello’
B. arr(4)=’Hello’
C. Elements of tuple cannot be changed
D. arr[5]=’Hello’
Answer: A
Q49. Which function opens file in python?
A. open()
B. Open()
C. new()
D. None of these
Answer: A
Q50. The function can be called in the program by writing function name followed by----
A. []
B. {}
C. ()
D. None of these
aNSWER: C
q51. Which of the following items are present in the function header?
A. Function name
B. Parameter list
C. Return value
D. Both a and b
aNSWER: d
q52. Choose the answer for statement 3
Import-----------------------# statement 1
Rect=[]
While True:
m=int(input(“Enter”))
nm=input(“Enter”)
Temp=[m,nm]
Rect.append(temp)
Ch=input(“Enter choice(Y?N”)
If ch.upper==”N”:
Break
F=open(stud.dat”,”--------------------------“) #statement 2
------------------------------.dump(rec,f) #statement 3
-----------------.close() #statement 4
A. unpickle
B. pickle
C. write
D. None of the Above
Answer: C
Q53. Choose the answer for statement 2
Import-----------------------# statement 1
rect=[]
While True:
m=int(input(“Enter”))
nm=input(“Enter”)
temp=[m,nm]
rect.append(temp)
ch=input(“Enter choice(Y?N”)
If ch.upper==”N”:
Break
F=open(stud.dat”,”--------------------------“) #statement 2
------------------------------.dump(rec,f) #statement 3
-----------------.close() #statement 4
A. w
B. wb
C. w+
D. write
Answer: B
Q54. What is the output of the following code?
import numpy as np
a=np.array([[1,2,3],[4,5,6],[7,8,9]])
print(a.shape)
A. (2,3)
B. (3,3)
C. (1,1)
D. None of Above
Answer: B
Q55. Which of the following are valid escape sequences in python?
A. \n
B. \t
C. \\
D. All of Above
Answer: D
Q56. Which of the following file can be opened in any text editor?
A. Binary
B. Text
C. Both of the Above
D. None of the Above
Answer: B
Q57. What is the output of the following?
x='abcd'
for i in range(x):
print(i)
A. a b c d
B. 0 1 2 3
C. Error
D. None of Above
Answer: C (string is not count as a interger)
Q58.What will be the output of following code?
x=['XX','YY']
for i in x:
i.lower()
print(x)
A. ['XX','YY']
B. [XX,YY]
C. ['xx','yy']
D. None of these
Answer: A
Q59. What will be the output of the following Python code?
from math import factorial
print(math.sqrt(25))
A. 5.0
B. Nothing is printed
C. Error
D. None of Above
Answer: C
Q60. What is the output of following code?
a1={1:"A",2:"B",3:"C"}
b1={4:"D",5:"E"}
b1.update(a1)
print(b1)
A. {4: 'D', 5: 'E', 1: 'A', 2: 'B', 3: 'C'}
B. {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', }
C. {4: 'D', 5: 'E'}
D. None of Above
Answer: A
Q61. Which of the following operators has the highest precedence?
A. &
B. *
C. Not
D. +
Answer: *
Q62. If a function does not have a return statement, which of the following does the function return?
A. int
B. null
C. An exception is thrown without return
D. None
Answer: D(Explanation: a function can exist without a return statement and returns none if the function doesn’t have a return statement.)
Q63.What is the output of the following python code?
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 above
Answer: C (AttributeError: 'int' object has no attribute 'upper')
Q64. What is the output when we execute print( list(“hello”))?
A. ['h', 'e', 'l', 'l', 'o']
B. [‘hello’]
C. [‘llo’]
D. [‘olleh’]
Answer: A
Q65. An algorithm represented in the form of programming language is----------------
A. Flowchart
B. Pseudo code
C. Program
D. None of Above
Answer: C( but reverse is not true)
Q66. What is the output of the following code?
i=2
while True:
if i%3==0:
break
print(i,end="")
i+=2
A. 2 4 6 8 10……….
B. 2 4
C. 2 3
D. Error
Answer: B
Q67. What is the output of the following code?
print(bool(0),bool(3.14159),bool(-3),bool(1.0+1j))
A. True True False True
B. False True True True
C. False True False True
D. False False False False
Answer: B
Q68. Which of following function takes two arguments?
A. load()
B. dump()
C. both of the above
D. none of the above
Answer: B
Q69. What is the output of the following code?
y="I Love python"
y[3]='s'
print(y)
A. snow
B. snow world
C. Error
D. snos world
Answer: C ('str' object does not support item assignment)
Q70. What does os.getlogin() return?
A. Name of the current user logged in
B. Gets a form to login as a different user
C. Name of the superuser
D. All of the above
Answer: A
Q71.What is the output of the following code?
a=50
b=a=a*5
print(b)
A. 250
B. 10
C. 50
D. Syntax Error
Answer: A
Q72. Which statement will read 5 characters from a file(file object ‘f’)?
A. f.read()
B. f.read(5)
C. f.reads(5)
D. None of the Above
Answer: B
Q73. Top-down approach is followed in structural programming?
A. True
B. False
C. Can’t say
D. May be
Answer: A
Q74.Hierarchy in a pseudo-code can be shown by--------
A. Curly Braces
B. Round Brackets
C. Indentation
D. Semicolon
Answer: C
Q75. In which data type, indexing is not valid?
A. List
B. Dictionary
C. String
D. None of above
Answer: B
Q76. What will be the output of the following pseudo code?
Integer a
Set a=5
do
print(a-2)
a=a-1
while (a not equals 0)
end while
A. 5 3 0
B. 3 0
C. Infinite loop
D. None of these
Answer: D (3 2 1 0 -1)
Q77. Ravi opened a file in Python using open () function but forgot to specify the mode. In which mode the file will open?
A. Write
B. Append
C. Read
D. Both read and write
Answer: C
Q78. Which 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*
Answer: B
Q79. What will be the output of the following Python code?
x=50
def func(x):
print('x is',x)
x=2
print('Changed local x to',x)
func(x)
print('x is now',x)
A. x is 50
Changed local x to 2
x is now 50
B. x is 50
Changed local x to 2
x is now 100
C. x is 50
Changed local x to 2
x is now 2
D. None of Above
Answer: A
Q80. The operation represented by a parallelogram is called as---------------------------
A. Input/Output
B. Comparison
C. Assignment
D. Conditions
Answer: A
Q81. Any algorithm is a program written according to proper syntax.
A. True
B. False
C. Can’t say
D. May be
Answer: B
Q82. What is the output of the following?
t=(2,3,4,3.5,5,6)
print(sum(t)+t.count(2))
A. 24.5
B. 24
C. 23.5
D. 25.5
Answer: 24.5
Q83. To repeat a particular task, we use--------------------
A. Input
B. Loop
C. Output
D. Condition
Answer: B
Q84. What will be the output of the following pseudo code, where represent XOR operation?
Integer a, b, c
Set b=5, a=1
c=a ^ b
print©
A. 4
B. 3
C. 5
D. 7
Answer: A
Q85. Software mistake during coding are known as ----------------------------
A. Errors
B. Bugs
C. Failures
D. Defects
Answer.B
Q86. What is the output of print((-3)**2)
A. -9
B. 6
C. -6
D. 9
Answer.9
Q87. Fill in the blank.
Import pickle
f=open(“data.dat”,’rb’)
d=--------------------------.load(f)
f.close()
A. unpickle
B. picking
C. pickle
D. pick
Answer: C
Q88. What is the purpose of the following code?
Import numpy as np
z=[1,2,3]
y=np.array(z)
A. To convert z to array
B. To convert z to list
C. Both of the above
D. None of the above
Answer: A
Q89. What will be the output of the following python code.
print(min(max(False,-3,-4),2,7))
A. -4
B. -3
C. 2
D. False
Answer: D
Q90. What is the output of the following Python code?
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
A. 0 1 2 3 4 Here
B. 0 1 2 3 4 5 Here
C. 0 1 2 3 4
D. 1 2 3 4 5
Answer: C
Q91. Which one of the following is the correct way of calling a function?
A. Function_name()
B. Call function_name()
C. Ret function_name()
D. Function function_name()
Answer: A
Q92.What is the output of the following Python code?
def sayHello():
print('Hello World!')
sayHello()
sayHello()
A. Hello World!
Hello World!
B. ‘Hello World!’
‘Hello World!’
C. Hello
Hello
D. None of the Above
Answer: A
Q93. Which keyword is used for function?
A. Fun
B. Def
C. Define
D. Function
Answer: B
Q94. What are the attributes of numpy array?
A. Shape,dtype,ndim
B. Objects, type list
C. Objects,non vectorization
D. Unicode and shape
Answer: A
Q95. Let us assume 4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?
a=4
b=11
print(a|b)
print(a>>2)
A. 15
1
B. 14
1
C. 17
2
D. 16
2
Answer: A (Bitwise right shift operator(>>): The a’s value is moved right by the 2 bits.)
Q96. Which module to be imported to make the following line functional?
Sys.stdout.write(“ABC”)
A. System
B. Stdin
C. Stdout
D. Sys
Answer: D
Q97. Which of the following is immutable data type?
A. List
B. Set
C. Tuple
D. Dict
Answer: C
Q98. What is the output of the following code?
a=set('abc')
b=set('cd')
print(a^b)
A. {'d', 'a', 'b'}
B. {a, b, c,d}
C. {'d', 'a', 'b'}
D. None of Above
Answer: C
Q99. Which of the following is correct?
A. Dictionary can have two same keys with different values
B. Dictionary can have two same values with different keys
C. Dictionary can have two same keys or same values but cannot have two same key value pair
D. Dictionary can neither have two same keys nor two same values
Answer: B
Q100.What will be the output of the following Python code?
from math import*
print(ceil(3.4))
A. 4
B. 5
C. 3.5
D. None of the Above
Answer: A
Comments