5 - 6255737462828565350 (10 Files Merged)
5 - 6255737462828565350 (10 Files Merged)
UNIT 1
1. Convert the following decimal number to 8-bit binary.
187
a) (10111011)2
b) (11011101)2
c) (10111101)2
d) (10111100)2
e) None of the above
Answer :a
a) (36.506)8
b) (36.206)8
c) (35.506)8
d) (35.206)8
e) None of the above
Answer :b
3. If the decimal number is a fraction then its binary equivalent is obtained by ________ the
number continuously by 2.
a) Dividing
b) Multiplying
c) Adding
d) Subtracting
e)None of the above
Answer :b
a) (346.25)10
b) (532.864)10
c) (340.67)10
d) (531.668)10
e)None of the above
Answer :a
5. Representation of hexadecimal number (6DE)H in decimal:
a) Comparator
b) Inverter
c) Adder
d) Subtractor
e)None of the above
Answer :b
7. The minimum decimal equivalent to 11C.0 is
a) 183
b) 194
c) 268
d) 296
e) None of the above
Answer :b
a) 100001110100
b) 010001111000
c) 100001000111
d) 011110000100
e) None of the above
Answer :a
a) AB+BC
b) A’B+AB’C
c) (A+B).(A+C)
d) AC+A’B
e) None of the above
Answer :c
10. A three variable truth table has high output for input 010,011 and 110. The Boolean
expression for SOP can be written as
a) A’B+BC’
b) AB’+B’C
c) (AB)’+BC
d) AB+(BC)’
e) None of the above
Answer :a
a) AND
b) POS
c) SOP
d) NAND
e)None of the above
Answer:b
a) 480
b) 483
c) 482
d) 484
e)None
Answer:c
a) (-16)10
b) (16)10
c) (11000000)2
d) (01000000)2
e) None of the above
Answer:d
Answer:c
a) 5
b) 3
c) 12
d) 6
e) None of the above
Answer:d
a) 101011
b) 110101
c) 011111
d) 111110
e) None of the above
Answer:d
17. The Boolean function Y=AB+CD is to be realized using 2 input NAND gates.The
minimum number of gates required is
a) 2
b) 3
c) 4
d) 5
e) 6
Answer:b
18. In the sum of product function f(XYZ)=∑m(2,3,4,5,), the prime implicants are
a) X’Y,XY’
b) X’Y,XY’Z’,XY’Z
c) X’YZ’,X’YZ,XY’
d) X’YZ’,X’YZ,XY’Z
e) None of the above
Answer: a
a) w,y,xz,x’z’
b) w,y,xz
c) y, x’y’z’
d) y, xz,x’z’
e) none of the above
Answer: d
a) ∑m(2,3,6,7)
b) ∑m(0,1,3,5)
c) ∑m(0,1,6,7)
d) ∑m(2,3,4,5)
e) None of the above
Answer:a
a) 111111001
b) 000000101
c) 111111010
d) 010101011
e) None of the above
Answer:b
a) 100011001010
b) 010110010111
c) 010110101101
d) 100010100111
e) None of the above
Answer:b
23. Product of sum expression can be implemented using:
Answer : a
a) Only A
b) C is correct
c) D is correct
d) Both C and D is correct
e) Only B is correct
Answer : d
25. The four variable function f in terms of min-terms as f(A,B,C,D)=
∑m(2,3,8,10,11,12,14,15).Using the K-map minimize the function in terms of SOP form
.also give the total number of two input NAND gate required to implement the function
Answer: b
a) A’B’+AB
b) A+B
c) AB+C’
d) A’+BC’
e) None of the above
Answer: a
Answer: b
a) F=(A+B’C’)(D’+E+F)
b) F=(A+BC’)(D’+E’+F)
c) F=(A+BC’)(D’+E+F)’
d) F=(A+BC’)(D’+E+F)
e) None of the above
Answer: d
Answer :c
Answer :b
UNIT 2
1. Which of the following logic expressions represents the logic diagram shown?
a) X=AB’+A’B
b) X=(AB)’+AB
c) X=(AB)’+A’B’
d) X=A’B’+AB
e)none of the above
Answer:d
a) Comparator
b) Multiplexer
c) Adder
d) Demultiplexer
e)none of the above
Answer:d
Answer: b
Answer :b
Answer :e
Answer :d
Answer :a
Answer :c
9. Why is parallel data transmission preferred over serial data transmission for most
applications?
a) It is much slower
b) It is cheaper
c) More people use it
d) It is much faster
e)All of the above
Answer :d
Answer: c
Answer: c
Answer: d
13. Consider a 4-to-1 multiplexer with two select lines S1 and S0, given belowThe minimal
sum-of-products form of the Boolean expression for the output F of the multiplexer is:
a) P'Q+QR'+PQ'R
b) P'Q + P'QR' +PQR'+ PQ’R
c) P’QR+P’QR’+PQ’R
d) PQR’
e) None of the above
Answer: a
14. Consider the circuit above. Which one of the following options correctly represents
f (x, y, z)?
a) xz’+xy+y’z
b) xz’+xy+(yz)’
c) xz+xy+(xy)’
d) xz+xy’+y’z
e) none othe above
Answer: a
15. Which of the following logic operations is performed by the following given
combinational circuit?
a) XOR
b) X-NOR
c) NAND
d) NOR
e) None of the above
Answer: a
16. The logic operations of two combinational circuits in Figure-I and Figure-II are
a) Entirely different
b) Identical
c) Complementary
d) Dual
e) None of the above
Answer: a
17. Minimum number of multiplexers required to realize the following function,f = A'B'C +
A'B'C' Assume that inputs are available only in true form and Boolean constant 1 and 0
are available.
a) 1
b) 2
c) 3
d) 4
e) None of the above
Answer: b
18. The BCD adder to add two decimal digits needs minimum of
a) 6 Full adder and 2 half adder
b) 5 Full adder and 2 half adder
c) 4 Full adder and 3 half adder
d) 3 Full adder and 2 half adder
e) None of the above
Answer: c
19. How many select lines are required for a 1-to-8 demultiplexer?
a) 2
b) 3
c) 4
d) 5
e)none of the above
Answer: b
Answer: b
21. Which of te following circuit comes under the class of combinational circuits? Select the
correct answer
1) Full subtractor
2) Full adder
3) Half adder
4) JK flip flop
5) Counter
a) Only 1
b) 4 and 5
c) 1,2,and3
d) 3 and 4
e) None of the above
Answer: c
22. What is the number of select line required in single input n-output demultiplexer?
a) 2
b) n
c) 2n
d) Log 2 n
e) None of the above
Answer: d
23. Two 16-input MUX drive 2-input MUX,what will be the total input lines?
a) 2-input MUX
b) 4-input MUX
c) 16-input MUX
d) 32-input MUX
e) None of the above
Answer: d
24. In a combinational circuit, the output at any time depends only on the _______ at that
time.
a) Voltage
b) Intermediate values
c) Input values
d) Clock pulses
e)none of the above
Answer :c
A. From the word description of the problem, identify the inputs and outputs and
draw a block diagram.
B. Draw the truth table such that it completely describes the operation of the
circuit for different combination of circuit
a) B, C, D, E, A
b) A, D, E, B, C
c) A, B, E, C, D
d) B, A, E, C, D
e)none of the above
Answer: c
Answer: a
27. Using four –input multiplexer, if BC is taken as Select line while implementing ,what
will be inputs,if the function f(A,B,C)= )=∑m(0,2,3,5,7)
a) I0,I1,I2,I3=A’,A,A’,1
b) I0,I1,I2,I3=A’,1,A’,1
c) I0,I1,I2,I3=A’,A’,0’,1
d) I0,I1,I2,I3=A’,0,0,1
e) None of the above
Answer: a
28. If A and B are the inputs of a half adder, the sum is given by __________
a) A AND B
b) A OR B
c) A XOR B
d) A EX-NOR B
e)none of the above
Answer: c
29. If A and B are the inputs of a half adder, the carry is given by __________
a) A AND B
b) A OR B
c) A XOR B
d) A EX-NOR B
e)none of the above
Answer: a
Answer: c
UNIT 3
Answer: d
2. For the counter of Q-1, the initial count is Q2 Q1 Q0= 000 . What is the count after 13
clock pulses?(in above question)
a) Q2 Q1 Q0= 000
b) Q2 Q1 Q0= 011
c) Q2 Q1 Q0= 010
d) Q2 Q1 Q0= 111
e) None of the above
Answer: b
Answer: c
4. The truth table for an S-R flip-flop has how many VALID entries?
a) 1
b) 2
c) 3
d) 4
e) not defined
Answer: c
5. What is meant by the parallel load of a shift register?
a) All FFs are preset with data
b) Each FF is loaded with data, one at a time
c) Parallel shifting of data
d) All FFs are set with data
e)none of the above
Answer: a
6. Assume that a 4-bit serial in/serial out shift register is initially clear. We wish to store the
nibble 1100. What will be the 4-bit pattern after the second clock pulse? (Right-most bit
first)
a) 1100
b) 0011
c) 0000
d) 1111
e)none of the above
Answer: c
7. The group of bits 11001 is serially shifted (right-most bit first) into a 5-bit parallel output
shift register with an initial state 01110. After three clock pulses, the register contains
________
a) 01110
b) 00001
c) 00101
d) 00110
e)none of the above
Answer: c
Answer: c
Answer: d
10. A shift register is defined as ___________
a) The register capable of shifting information to another register
b) The register capable of shifting information either to the right or to the left
c) The register capable of shifting information to the right only
d) The register capable of shifting information to the left only
e)none of these
Answer: b
11. Which flip flop is used to over come the race around condition?
a)S R flip flop
b)J K flip flop
c)Master Slave flip flop
d)D flip flop
e)none of these
Answer: c
Answer: a
13. The difference between a combinational circuit and a flip-flop is that _____________
a) The flip-flop requires previous state
b) The flip-flop requires next state
c) The flip-flop requires a clock pulse
d) The flip-flop depends on the past as well as present states
e)none of these
Answer: c
14. The minimum number of flip-flops that can be used to construct a modulus-5 counter is
a) 3
b) 8
c) 5
d) 10
e)none
Answer :a
15. MOD-16 counter requires ________ no. of states.
a) 8
b) 4
c) 16
d) 32
e)64
Answer :c
Answer: c
Answer :a
Answer :a
Answer :b
21. The digital circuit as shown in figure below represents to which one of the following?
a) J-K flip-flop
b) S-R flip-flop
c) T flip-flop
d) Master-slave flip-flop
e) None of these
Answer :b
22. If tp is pulse width ,td is propagation delay,T is the period of pulse train then which of the
following condition can avoid the race around condition?
a) 2tp > td>T
b) tp = td=T
c) 2tp < td<T
d) 2tp < td>T
e) None of the above
Answer :d
23. Characteristic equation of T flip flop is given by:
a) Qn+1= TQn’ + T’ Qn
b) Qn+1= T + T’ Qn
c) Qn+1= (TQn)’ + T’ Qn
d) Qn+1= (TQn)’
e) None of the above.
Answer :a
24. In a J-K flip_ flop we have J=Q’ and K= 1(as shown in figure ).Assuming flip flop was
initially cleared and then clocks for 6 –pulses, the sequence at the Q output will be:
a) 010000
b) 110010
c) 010101
d) 101010
e) None of the above
Answer :d
25. When the flip flop is reset then the output will be:
a) Q= 1 and Q’ = 0
b) Q= 0 and Q’ = 0
c) Q= 1 and Q’ = 1
d) Q= 0 and Q’ = 1
e) None of the above
Answer :d
26. Assertion (A):The indeterminate condition of J-K flip flop is permitted in S-R flip flop.
Reason( R):A J K flip flop has a characteristic similar to that of an S-R flip flop.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, and R is not the correct explanation of A
c) A is true but R is false
d) A is false but R is true
e) None of these
Answer :d
Answer :a
28. A 4-bit ripple counter consists of flip flops that each have propagation delay of 12 ns
from clock to Q output For the counter to recycle from
1111 to 000, it takes a total of :
a) 12 ns
b) 24 ns
c) 48 ns
d) 26 ns
e) None of the above
Answer :c
29. A pulse train with a frequency of 1 MHz is counted using mod 1024 ripple counter built
with J-K flip flops. For proper operation of counter the maximum permission able
propagation delay per flip flop stage is:
a) 100ns
b) 20 ns
c) 10ns
d) 50ns
e) None of the above
Answer :a
Answer: c
Answer: b
3. If the output of a digital circuit makes a momentary transition to logic 1,while otherwise
the output is logic 0,it is called a
a) Static-1 hazard
b) Static-0 hazard
c) Dynamic hazard
d) No hazard
e) All of the above
Answer: b
Answer: b
Answer: b
Answer: c
Answer: c
8. For designing a finite state machine K-map can be used for minimizing the :
a) Excitation expression of flip flop
b) No. of flip flpos
c) Output logic expression
d) All of the above
e) None of the above
Answer: a
10. A 4-bit ripple counter consists of flip-flops, which each have a propagation delay from
clock to Q output of 15 ns. For the counter to recycle from 1111 to 0000, it takes a total
of ________
a) 15 ns
b) 30 ns
c) 45 ns
d) 60 ns
e)none of the above
Answer: d
Answer: a
12. A reliable method for eliminating decoder spikes is the technique called ________
a) Strobing
b) Feeding
c) Wagging
d) Waving
e) none of the above
Answer: a
13. Assume a 4-bit ripple counter has a failure in the second flip-flop such that it “locks up”.
The third and fourth stages will __________
a) Continue to count with correct outputs
b) Continue to count but have incorrect outputs
c) Stop counting
d) Turn into molten silicon
e) none of the above
Answer: c
Answer: d
15. What is a state diagram?
a) It provides the graphical representation of states
b) It provides exactly the same information as the state table
c) It is same as the truth table
d) It is similar to the characteristic equation
e) none of the above
Answer: b
Answer: d
Answer: c
Answer: a
Answer: a
20. An asynchronous binary up counter, made from a series of leading edge-triggered flip-
flops, can be changed to a down counter by ________
a) Taking the output on the other side of the flip-flops (instead of Q)
b) Clocking of each succeeding flip-flop from the other side (instead of Q)
c) Changing the flip-flops to trailing edge triggering
d) All of the Mentioned
e)none of the above
Answer: d
21. A 4-bit binary up counter has an input clock frequency of 20 kHz. The frequency of the
most significant bit is ________
a) 1.25 kHz
b) 2.50 kHz
c) 160 kHz
d) 320 kHz
e) none of the above
Answer: a
22. Why is the extent of propagation delay in synchronous counter much lesser than that of
asynchronous counter?
a) Due to clocking of all flip flops at the same instant
b) Due to increase in number of states
c) Due to absence of connection between output of preceding flip flop and clock of
next one
d) Due to absence of mode control operation.
e) none of the above
Answer: a
Answer: a
24. On which factor/s does the clock pulse frequency of a counter depend/s for its reliable
operation?
a) Number of flip flops
b) Width of strobe pulse
c) Propagation delay
d) All of the above
e) none of the above
Answer: d
25. From the diagram shown below, if the circuit enters into state '5', its next state will be '7'.
If the circuit further enters at state'7', then what would be the desirable next state for
avoiding the lock out condition?
a) 0
b) 3
c) 5
d) 7
e) none of the above
Answer: a
26. How many 'D' flip flops will be required for designing the synchronous counter for the
state diagram shown below?
a) 2
b) 3
c) 5
d) 7
e) none of the above
Answer: b
27. Which among the following are the sequential circuits entering into the phenomenon of
lock out condition?
a) Bush circuits
b) Bushless circuits
c) Locked circuits
d) Unlocked circuits
e) none of the above
Answer: b
28. If the number of states in a counter are 2n, then the value of 'n' is ________
a) Less than the number of flip flops
b) Greater than the number of flip flops
c) Equal to the number of flip flops
d) Unpredictable
e) none of the above
Answer: c
29. From the generalized schematic of Moore circuit given below, what does the
combinational circuit 'C1' known as?
Answer: c
30. According to Moore circuit, the output of synchronous sequential circuit depend/s on
______ of flip flop
a) Past state
b) Present state
c) Next state
d) External inputs
e) none of the above
Answer: b
UNIT 4
1. The FPGA refers to ____________
a) First programmable Gate Array
b) Field Programmable Gate Array
c) First Program Gate Array
d) Field Program Gate Array
e) none of the above
Answer – b
Answer – d
Answer: d
Answer: c
5. PLA contains:
a) AND and OR arrays
b) NAND and OR arrays
c) NOT and AND arrays
d) NOR and OR arrays
e) none of the above
Answer: a
6. PLA refers to _________
a) Programmable Loaded Array
b) Programmable Array Logic
c) Programmable Logic Array
d) Programmed Array Logic
e) none of the above
Answer: c
7. Permanent instructions that the computer uses when it is turned ON and that cannot be
changed by other instructions are contained in
a) ROM
b) RAM
c) ALU
d) SRAM
e) none of the above
Answer: a
Answer: a
9. Which of the following control signals are selected for read and write operations in a
RAM?
a) Data buffer
b) Chip select
c) Read and write
d) Memory
e) none of the above
Answer: c
10. How many 1024 * 1 RAM chips are required to construct a 1024 * 8 memory system?
a) 4
b) 6
c) 8
d) 12
e) none of the above
Answer: c
11. How many 16K * 4 RAMs are required to achieve a memory with a capacity of 64K and
a word length of 8 bits?
a) 2
b) 4
c) 6
d) 8
e) none of the above
Answer: d
Answer: c
13. In PLD, there are provisions to perform interconnections of the gates internally, because
of _________
a) High reliability
b) High conductivity
c) The desired logic implementation
d) The desired output
e) none of the above
Answer: c
Answer: c
Answer: b
Answer: c
Answer: c
Answer: b
Answer: a
Answer: a
21. The equivalent of emitter-coupled logic made out of FETs is called __________
a) CML
b) SCFL
c) FECL
d) EFCL
e) none of the above
Answer: b
Answer: c
23. Integrated injection logic is a class of digital circuits built with __________
a) Single collector BJT
b) Double emitter BJT
c) Multiple emitter BJT
d) Multiple collector BJT
e) none of the above
Answer: d
Answer: a
Answer: c
26. The full form of CMOS is ____________
a) Capacitive metal oxide semiconductor
b) Capacitive metallic oxide semiconductor
c) Complementary metal oxide semiconductor
d) Complemented metal oxide semiconductor
e) none of the above
Answer: c
27. Two important characteristics of CMOS devices are ____________
a) High noise immunity
b) Low static power consumption
c) High resistivity
d) Both high noise immunity and low static power consumption
e) none of the above
Answer: d
Answer: a
Answer: c
1|P a g e
PYTHON PROGRAMING (KNC – 402)
UNIT 1
MULTIPLE CHOICE QUESTIONS ANSWERS
2|P a g e
8. What is used to define a block of code in Python?
A. Parenthesis
B. Indentation
C. Curly braces
D. None of the above
3|P a g e
16. Which of the following is an invalid variable?
a) my_string_1
b) 1st_string
c) foo
d) _
17. Why are local variable names beginning with an underscore discouraged?
a) they are used to indicate a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
d) they slow down execution
24. Given a function that does not return any value, What value is thrown by default when
executed in shell.
a) int
b) bool
c) void
4|P a g e
d) None
>>>str="hello"
>>>str[:2]
a) he
b) lo
c) olleh
d) hello
28. In python we do not specify types, it is directly interpreted by the compiler, so consider the
following operation to be performed.
>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned
29. What error occurs when you execute the following Python code snippet?
apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
30. What will be the output of the following Python code snippet?
def example(a):
a = a + '2'
a = a*2
return a
>>>example("hello")
a) indentation Error
5|P a g e
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2
32. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
34. The following is displayed by a print function call. Select all of the function calls that result
in this output.
1. tom
2. dick
3. harry
a) print('''tom
\ndick
\nharry''')
b) print(”’tomdickharry”’)
c) print(‘tom\ndick\nharry’)
d) print('tom
dick
harry')
35. What is the average value of the following Python code snippet?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
a) 85.0
b) 85.1
c) 95.0
d) 95.1
6|P a g e
b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)
38. How we can convert the given list into the set ?
a) list.set()
b) set.list()
c) set(list)
d) None of the above
42. Which of the following can convert the string to float number ?
a) str(float,x)
b) float(str,int)
c) int(float(str))
d) float(str)
43. Which of the following function are used to convert the string into the list ?
a) map()
b) convertor()
c) split()
d) lambda
7|P a g e
a) int
b) list
c) dictionary
d) All of the above
ANSWERS
1.a 2.c 3.a 4.b 5.a 6.b 7.d 8.b 9.c 10.b 11.b 12.c 13.a 14.d 15.d
16.b 17.a (As Python has no concept of private variables, leading underscores are used to indicate
variables that must not be accessed from outside the class.) 18.a (eval can be used as a variable)
19.d 20.a 21b 22.b 23.d 24.d 25.a 26.a 27.a 28.d
29.b 30.a 31.a 32.d 33.c 34.c 35.a 36.c 37.a 38.c
39.c 40.d 41.c 42.d 43.c 44.d 45.d 46.d
8|P a g e
5. Mathematical operations can be performed on a string.
a) True
b) False
10. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
9|P a g e
15. What does ~~~~~~5 evaluate to?
a) +5
b) -11
c) +11
d) -5
21. What will be the output of the following Python code snippet if x=1?
x<<2
a) 8
b) 1
c) 2
d) 4
23. What will be the value of x in the following Python expression, if the result of
10 | P a g e
that expression is 2?
x>>2
a) 8
b) 4
c) 2
d) 1
24. What will be the output of the following Python expression if x=15 and y=12?
x&y
a) b1101
b) 0b1101
c) 12
d) 1101
26. Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are
1.
a) OR
b) AND
c) XOR
d) NOT
28. What will be the output of the following Python code if a=10 and b =20?
a=10
b=20
a=a^b
b=a^b
a=a^bprint(a,b)
a) 10 20
b) 10 10
c) 20 10
d) 20 20
11 | P a g e
~100?
a) 101
b) -101
c) 100
d) -100
30. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.
a) True
b) False
33. Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **
12 | P a g e
b) %
c) //
d) |
42. Which of the following expressions involves coercion when evaluated in Python?
a) 4.7 – 1.5
b) 7.9 * 6.3
c) 1.7 % 2
d) 3.4 + 4.6
13 | P a g e
43. What will be the output of the following Python expression?
24//6%3, 24//4//2
a) (1,3)
b) (0,3)
c) (1,0)
d) (3,1)
44. Which among the following list of operators has the highest precedence?
+, -, **, %, /, <<, >>, |
a) <<, >>
b) **
c) |
d) %
14 | P a g e
ANSWERS:
1.b 2.b 3.a 4.b 5.b 6.a 7.c 8.a 9.a 10.d 11.b 12.c
13.c 14.a 15.a 16.d 17.a 18.d 19.d 20.d 21.d 22.b
23.a 24.c 25.b 26.c 27.c 28.c 29.b 30.a 31.b 32.b
33.d 34.b 35.a 36.c 37.d 38.a 39.b 40.b 41.d 42.c
43.a 44.b 45.c 46.a 47.d 48.b 49.b
15 | P a g e
UNIT II
a. Yes
b. No
c. if/else not used in python
d. None of the above
16 | P a g e
a. pq
b. rs
c. pqrs
d. pq12
a. if a = b:
b. if a == b:
c. if a === c:
d. if a == b
11. What will be the output of given Python code?
str1="hello"
c=0
for x in str1:
if(x!="l"):
c=c+1
else:
pass print(c)
a. 2
b. 0
c. 4
d. 3
12. What does the following code print to the console?
if 5 > 10:
print("fan")
elif 8 != 9:
print("glass")
else:
print("cream")
a. Cream
B. Glass
c. Fan
d. No output
17 | P a g e
a. usa b. ireland
c.colombia d. None of the above
18 | P a g e
print("Audi")
a. Nissan b. Ford
c. BMW d. Audi
1.a 2.a 3.a 4.b 5.c 6.c 7.a (Yes, we can write if/else in one
line. For eg i = 5 if a > 7 else 0. So, option A is correct.) 8.b 9.a ( If condition
is true so pq will be the output. So, option A is correct.) 10.b 11.d 12.b
13.c 14.a 15.d 16.c 17.b (The first elif that is True will be
executed when multiple elif statements are True.) 18.a (1 does not equal True, but it's
considered True in a boolean context. Values that are considered True in a boolean
context are called "truthy" and values that are considered False in a boolean context are
called "falsy".) 19. c 20. D
19 | P a g e
1.Which of the following is the loop in python ?
A. For
B. while
C. do while
D.1 and 2
7. What is the final value of the i after this, for i in range(3): pass
A. 1
B. 2
C. 3
D. 0
20 | P a g e
A. a b c d
B. A B C D
C. a B C D
D. error
13. What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)
A. a
B. abcd abcd abcd
C. a a a a
D. None of the mentioned
21 | P a g e
15. What will be the output of the following Python code?
x = 123
for i in x:
print(i)
A. 1 2 3
B. 123
C. error
D. None of the mentioned
17. What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
print (i)
A. 1234
B. 4321
C. error
D. none of the mentioned
A. 0.0 1.0
B. 0 1
C. error
D. none of the mentioned
19. What will be the output of the following Python code snippet?
x=2
for i in range(x):
x += 1
print (x)
A. 01234
B. 01
C. 3 4
D. 0 1 2 3
20. What will be the output of the following Python code snippet?
x=2
for i in range(x):
x -= 2
22 | P a g e
print (x)
A. 01234
B. 0 -2
C. 30
D. Error
A. 0 1 2 3 4 Here
B. 0 1 2 3 4 5 Here
C. 0 1 2 3 4
D. 0 1 2 3 4 5
ANSWERS :
1. D 2. C 3. A 4. A 5. D 6. C 7. B 8. D 9. B 10.
A 11. B 12.D ( The loop does not terminate as new elements are being added to the list in
each iteration.) 13.C ( range() is computed only at the time of entering the loop.) 14.D
15.C (Objects of type int are not iterable.) 16. C ( Object of type float cannot be
interpreted as an integer.) 17.B 18.B 19.C 20.B 21.C
23 | P a g e
B. 1
C. 3
D. infinite
A. no output
B. i i i i i i …
C. a b c d e f
D. abcdef
A. 123456
B. 1234567
C. error
D. none of the mentioned
A. True
24 | P a g e
B. False
C. None
D. none of the mentioned
A. 0120
B. 012
C. None
D. none of the mentioned
A. a b c d e f
B. Abcdef
C. i i i i i i...
D. Error
A. a a a a a a
B. a a a a
C. i i i i i i
D. None of the mentioned
A. 1 2
B. 1 2 3
C. Error
D. None of the mentioned
25 | P a g e
i=1
while True: if i%O.7 == 0: break print(i) i += 1
A. 1 2 3 4 5 6
B. 1 2 3 4 5 6 7
C. Error
D. None of the mentioned
A. 5 6 7 8 9 10
B. 5 6 7 8
C. 5 6
D. Error
A. 1
B. 1 2
C. 1 2 3 4 5 6 ....
D. 1 3 5 7 9 11 ....
A. 2 4 6 8 10 ....
B. 2 4
C. 2 3
D. Error
26 | P a g e
A. 1
B. 1 3 5 7 ...
C. 1 2 3 4 ....
D. none of the mentioned
A. true
B. false
C. error
D. none of the mentioned
A. 0 1 2 0
B. 0 1 2
C. error
D. none of the mentioned
A. 0 1 2 3 0
B. 0 1 2 0
C. 0 1 2
D. error
A. a a a a a a
27 | P a g e
B. a
C. no output
D. error
ANSWERS :
A. 4.5
B. 5
C. 4
D. 4.6
A. (x**y)**z
B. (x**y)/z
C. (x**y)%z
D. (x**y)*z
A. Error
B. True
C. False
D. 0
A. Error
28 | P a g e
B. True
C. False
D. 4>2
A. Error
B. -5
C. 5
D. 5.0
A. Error,6
B. 12, Error
C. 12,6
D. Error, Error
A. 2
B. False
C. -3
D. -4
A. a Error
B. ‘a’ Error
C. Error a
D. Error Error
A. Error
B. 1
C. 2j
D. 1+2j
11. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
A. (a%b,a//b)
B. (a//b,a%b)
C. (a//b,a*b)
D. (a/b,a%b)
29 | P a g e
A. Error
B. [(1,2),(2,3)]
C. [(0,2),(1,3)]
D. [(2,3)]
13. Which of the following functions does not necessarily accept only iterables as arguments?
A. enumerate()
B. all()
C. chr()
D. max()
A. ord()
B. min()
C. chr()
D. any()
15. Which of the following functions will not result in an error when no arguments are passed
to it?
A. min()
B. divmod()
C. all()
D. float()
A. f
B. OxF
C. OXf
D. Oxf
A. 4
B. 3
C. Error
D. 6
30 | P a g e
B. Define
C. Def
D. Function
def sayHello():
print('Hello World!')
sayHello()
sayHello()
A. 3
B. 4
C. 4 is maximum
D. None of the mentioned
A. x is now 50
B. x is now 2
C. x is now 100
D. None of the mentioned
31 | P a g e
say('Hello')
say('World', 5)
A. Hello WorldWorldWorldWorldWorld
B. Hello World 5
C. Hello World,World,World,World,World
D. Hello HelloHelloHelloHelloHello
32 | P a g e
A. Id returns the identity of the object
B. Every object doesn’t have a unique id
C. All of the mentioned
D. None of the mentioned
def cube(x):
return x * x * x
x = cube(3)
print x
A. 9
B. 3
C. 27
D. 30
def C2F(c):
return c * 9/5 + 32
print C2F(100)
print C2F(0)
A. 212
32
B. 314
24
C. 567
98
D. None of the mentioned
33 | P a g e
A. 212
32
B. 9
27
C. 567
98
D. None of the mentioned.
37. 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
34 | P a g e
return total
total = 0print(foo())
A. 0
B. 1
C. error
D. none of the mentioned
35 | P a g e
x+=1
print(x)
x=12print("x")
A. Error
B. 13
C. 13
x
D. X
36 | P a g e
D. 5 10 15 40
53. Read the following Python code carefully and point out the global variables?
y, z = 1, 2def f():
global x
x = y+z
A. x
B. y and z
C. x, y and z
D. Neither x, nor y, nor z
54. Which of the following data structures is returned by the functions globals() and locals()?
37 | P a g e
A. list
B. set
C. dictionary
D. tuple
56. What happens if a local variable exists with the same name as the global variable you want to
access?
A. Error
B. The local variable is shadowed.
C. Undefined behavior.
D. The global variable is shadowed.
ANSWERS :
38 | P a g e
"abcd"[2:]
a)a
b)ab
c)cd
d) dc
Answer: c
3. The output of executing string.ascii_letters can also be achieved by:
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase
Answer: b
a) olleh
b) hello
c) h
d) o
Answer: d
5. What arithmetic operators cannot be used with strings?
a)+
b)*
c) –
d) All of the mentioned
Answer: c
6. 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
7. What will be the output of the following Python statement?
>>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
Answer: c
8. What will be the output of the following Python code?
>>>str1="helloworld"
>>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
Answer: a
9. print(0xA + 0xB + 0xC):
39 | P a g e
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
Answer: d
10. What will be the output of the following Python code?
>>>example = "snow world"
>>>print("%s" % example[4:7])
a) wo
b) world
c) sn
d) rl
Answer: a
11. What will be the output of the following Python code?
>>>example = "snow world"
>>>example[3] = 's'
>>>print example
a) snow
b) snow world
c) Error
d) snos world
Answer: c
40 | P a g e
>>example="helloworld"
>>example[::-1].startswith("d")
a) dlrowolleh
b) True
c) -1
d) None
Answer: b
17. To concatenate two strings to a third what statements are applicable?
a)s3=s1s2
b)s3=s1.add(s2)
c)s3=s1.__add__(s2)
d) s3 = s1 * s2
Answer: c
Explanation: __add__ is another method that can be used for concatenation.
18. Which of the following statement prints hello\example\test.txt?
a)print(“hello\example\test.txt”)
b)print(“hello\\example\\test.txt”)
c)print(“hello\”example\”test.txt”)
d) print(“hello”\example”\test.txt”)
Answer: b
Explanation: \is used to indicate that the next \ is not an escape sequence.
19. Suppose s is “\t\tWorld\n”, what is s.strip()?
a)\t\tWorld\n
b)\t\tWorld\n
c)\t\tWORLD\n
d) World
Answer: d
20. The format function, when applied on a string returns ___________
a) Error
b) int
c) bool
d) str
Answer: d
21. What will be the output of the “hello” +1+2+3?
a) hello123
b) hello
c) Error
d) hello6
Answer: c
22. What will be the output of the following Python code?
>>>print("D", end = ' ')
>>>print("C", end = ' ')
>>>print("B", end = ' ')
>>>print("A", end = ' ')
a) DCBA
b) A,B,C,D
c) DCBA
d) D, C, B, A will be displayed on four lines
Answer: c
23. What will be displayed by print(ord(‘b’) – ord(‘a’))?
a)0
b)1
c)-1
41 | P a g e
d) 2
Answer: b
Explanation: ASCII value of b is one more than a. Hence the output of this code is 98-97, which is
equal to 1.
24. Say s=”hello” what will be the return value of type(s)?
a) int
b) bool
c) str
d) String
Answer: c
25. What is “Hello”.replace(“l”, “e”)?
a) Heeeo
b) Heelo
c) Heleo
d) None
26. To retrieve the character at index 3 from string s=”Hello” what command do we execute
(multiple answers allowed)?
a) s[]
b) s.getitem(3)
c) s.__getitem__(3)
d) s.getItem(3)
27. To return the length of string s what command do we execute?
a) s.__len__()
b) len(s)
c) size(s)
d) s.size()
28. Suppose i is 5 and j is 4, i + j is same as ________
a) i.__add(j)
b) i.__add__(j)
c) i.__Add(j)
d) i.__ADD(j)
42 | P a g e
32. What will be the output of the following Python code?
print("xyyzxyzxzxyy".count('yy', 2))
a) 2
b) 0
c) 1
d) none of the mentioned
Explanation: Counts the number of times the substring ‘yy’ is present in the given string, starting from
position 2.
33. What will be the output of the following Python code?
print("xyyzxyzxzxyy".endswith("xyy"))
a) 1
b) True
c) 3
d) 2
34. What will be the output of the following Python code?
print("abcdef".find("cd"))
a) True
b) 2
c) 3
d) None of the mentioned
43 | P a g e
d) Error
40. What will be the output of the following Python code snippet?
print('for'.isidentifier())
a) True
b) False
c) None
d) Error
41. What will be the output of the following Python code snippet?
print('abc'.islower())
a) True
b) False
c) None
d) Error
42. What will be the output of the following Python code snippet?
print('11'.isnumeric())
a) True
b) False
c) None
d) Error
43. What will be the output of the following Python code snippet?
print('HelloWorld'.istitle())
a) True
b) False
c) None
d) Error
44. What will be the output of the following Python code snippet?
print('abcdef12'.replace('cd', '12'))
a) ab12ef12
b) abcdef12
c) ab12efcd
d) none of the mentioned
45. What will be the output of the following Python code snippet?
print('Ab!2'.swapcase())
a) AB!@
b) ab12
c) aB!2
d) aB1@
ANSWERS :
1.d 2.c 3.b 4.d 5.c 6.b 7.c 8.a 9.d 10.a 11.c 12.d 13.a
14.c 15.b 16.b 17.c 18.b 19.d 20.d 21.c 22.c 23.b
24.c 25.a 26.c 27.a 28.b 29.a 30.c 31.a 32.c 33.b
34.b 35.a 36.a 37.a 38.b 39.b 40.a 41.a 42.a 43.b
44.a 45.c
44 | P a g e
MULTIPLE CHOICE QUESTIONS ANSWERS
45 | P a g e
d) “peter”
46 | P a g e
d) Error, < operator is valid for tuples but not if there are sub-tuples
47 | P a g e
c)(0,1)
d) (0,2)
48 | P a g e
24. Is the following Python code valid?
a=2,3,4,5
a
a)Yes, 2 is printed
b)Yes, [2,3,4,5] is printed
c)No, too many values to unpack
d) Yes, (2,3,4,5) is printed
1.b 2.b 3.c 4.c 5.c 6.a 7.a 8.b 9.d(Tuples are immutable and
don’t have an append method. An exception is thrown in this case.) 10.b 11.d
12.a 13.c 14.d 15.c 16.c 17.b 18.c 19.a 20.c(A tuple
needn’t be enclosed in parenthesis.) 21.c (For unpacking to happen, the number of
values of the right hand side must be equal to the number of variables on the left hand
side.) 22.b 23.c 24.d 25.d (A tuple is immutable thus it doesn’t have
a sort attribute.) 26.c (Tuple doesn’t have any update() attribute because it is
immutable.) 27.a (A list of tuples is a list itself. Hence items of a list can be
sorted.)
49 | P a g e
MULTIPLE CHOICE QUESTIONS ANSWERS
8. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing
operation?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned
50 | P a g e
9. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error
b) None
c) 25
d) 2
10. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]
51 | P a g e
17. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
a) 0
b) 1
c) 4
d) 2
19. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?
a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [25, 20, 5, 5, 4, 3, 3, 1]
d) [3, 1, 25, 5, 20, 5, 4, 3]
20. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34,
5])?
a) [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
b) [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
c) [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
d) [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
21. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?
a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]
22. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?
a) [3, 4, 5, 20, 5, 25, 1]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]
52 | P a g e
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i
print(indexOfMax)
a) 1
b) 2
c) 3
d) 4
29. which of the following the “in” operator can be used to check if an item is in it?
a) Lists
b) Dictionary
c) Set
d) All of the mentioned
53 | P a g e
c) 5
d) 8
54 | P a g e
print(lst)
a) [3, 7, 8, 6, 1, 2]
b) Syntax error
c) [3,[7,8],6,1,2]
d) [3,4,6,7,8]
ANSWERS :
1.d 2.a 3.a 4.c 5.d 6.c 7.c 8.d 9.c 10.a 11.d 12.c 13.b 14.b 15.b 16.a
17.d 18.d 19.d 20.a 21.c 22.a 23.a 24.a
25.a 26.b 27.c 28.b 29.d 30.d 31.d 32.d 33.c 34.b
35.c 36.a 37.b 38.a 39.b
55 | P a g e
d) [0.0, 0.5, 1.0, 1.5, 2.0]
56 | P a g e
7. What will be the output of the following Python code snippet?
10. Which of the following is the same as list(map(lambda x: x**-1, [1, 2, 3]))?
a) [x**-1 for x in [(1, 2, 3)]]
b) [1/x for x in [(1, 2, 3)]]
c) [1/x for x in (1, 2, 3)]
d) error
l1=[1,2,3]
l2=[4,5,6]
[x*y for x in l1 for y in l2]
a) [4, 8, 12, 5, 10, 15, 6, 12, 18]
b) [4, 10, 18]
c) [4, 5, 6, 8, 10, 12, 12, 15, 18]
d) [18, 12, 6, 15, 10, 5, 12, 8, 4]
12. Write the list comprehension to pick out only negative integers from a
given list ‘l’.
57 | P a g e
a) [x<0 in l]
b) [x for x<0 in l]
c) [x in l for x<0]
d) [x for x in l if x<0]
13. Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9].
a) [x**3 for x in l]
b) [x^3 for x in l]
c) [x**3 in l]
d) [x^3 in l]
14. Read the information given below carefully and write a list comprehension such
that the output is: [‘e’, ‘o’]
w="hello"
v=('a', 'e', 'i', 'o', 'u')
a) [x for w in v if x in v]
b) [x for x in w if x in v]
c) [x for x in v if w in v]
d) [x for v in w for x in w]
t=32.00
[round((x-32)*5/9) for x in t]
a) [0]
b) 0
c) [0.00]
d) Error
16. Write a list comprehension for producing a list of numbers between 1 and 1000
that are divisible by 3.
a) [x in range(1, 1000) if x%3==0]
b) [x for x in range(1000) if x%3==0]
c) [x%3 for x in range(1, 1000)]
d) [x%3=0 for x in range(1, 1000)]
58 | P a g e
18. What will be the output of the following Python list comprehension?
20. Write a list comprehension equivalent for the Python code shown below.
1.c 2.b 3.c 4.c 5.b 6.b 7.a 8.a 9.c 10.c 11.c 12.d 13.a
14.b 15.d 16.b 17.a 18.c 19.b 20.b
2. Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
59 | P a g e
c) set((1,2,3,4))
d) {1,2,3,4}
60 | P a g e
c) Error as unsupported operand type for set data type
d) Error as the duplicate item 6 is present in both sets
61 | P a g e
d) Error, duplicate item present in list
62 | P a g e
c) 6
d) Nothing is displayed
27. Which of the following functions will return the symmetric difference between two sets, x
and y?
a) x|y
b) x^y
c) x&y
d) x – y
28. What will be the output of the following Python code snippet?
z=set('abc$de')
63 | P a g e
'a' in z
a) True
b) False
c) Nooutput
d) Error
29. What will be the output of the following Python code snippet?
s=set([1, 2, 3])
s.union([4, 5])
s|([4, 5])
a) {1, 2, 3, 4, 5}
{1, 2, 3, 4, 5}
b) Error
{1, 2, 3, 4, 5}
c) {1, 2, 3, 4, 5}
Error
d) Error
Error
30. What will be the output of the following Python code snippet?
for x in set('pqr'):
print(x*2)
a) pp
qq
rr
b) pqr
pqr
c) ppqqrr
d) pqrpqr
31. What will be the output of the following Python code snippet?
{a**2 for a in range(4)}
a) {1,4,9,16}
b) {0,1,4,9,16}
c) Error
d) {0, 1, 4, 9}
32. The ____________ function removes the first element of a set and the last element of a list.
a) remove
b) pop
c) discard
d) dispose
33. The difference between the functions discard and remove is that:
a) Discard removes the last element of the set whereas remove removes the first element of the set
b) Discard throws an error if the specified element is not present in the set whereas remove does
not throw an error in case of absence of the specified element
c) Remove removes the last element of the set whereas discard removes the first element of the
set
d) Remove throws an error if the specified element is not present in the set whereas discard does
not throw an error in case of absence of the specified element
34. If we have two sets, s1 and s2, and we want to check if all the elements of s1 are present in s2
or not, we can use the function:
64 | P a g e
a) s2.issubset(s1)
b) s2.issuperset(s1)
c) s1.issuperset(s2)
d) s1.isset(s2)
35. What will be the output of the following Python code, if s1= {1, 2, 3}?
s1.issubset(s1)
a) True
b) Error
c) Nooutput
d) False
1.d 2.a 3.c 4.b 5.b 6.d 7.b 8.c 9.a 10.d 11.a 12.d 13.c
14.a 15.b 16.a 17.c 18.d 19.b 20.c 21.b 22.a 23.a 24.c
25.b 26.d 27.b 28.a 29.c 30.a 31.d 32.b 33.d
34.b 35.a
65 | P a g e
5. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a) True
b) False
c) Error
d) None
7. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we
use?
a) d.delete(“john”:40)
b) d.delete(“john”)
c) del d[“john”]
d) del d(“john”:40)
10. Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using
the expression d[“susan”]?
a) Since “susan” is not a value in the set, Python raises a KeyError exception
b) It is executed fine and no exception is raised, and it returns None
c) Since “susan” is not a key in the set, Python raises a KeyError exception
d) Since “susan” is not a key in the set, Python raises a syntax error
66 | P a g e
12. Which of the following is not a declaration of the dictionary?
a) {1:‘A’,2:‘B’}
b) dict([[1,”A”],[2,”B”]])
c) {1,”A”,2”B”}
d) { }
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) 1A2B3C
b) 123
c) ABC
d) 1:”A” 2:”B” 3:”C”
14. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
a) 1
b) A
c) 4
d) Invalid syntax for get method
67 | P a g e
18. Which of the following isn’t true about dictionary keys?
a) More than one key isn’t allowed
b) Keys must be immutable
c) Keys must be integers
d) When duplicate keys encountered, the last assignment wins
24. What will be the output of the following Python code snippet?
>>> a={1:"A",2:"B",3:"C"}
>>> del a
a) method del doesn’t exist for the dictionary
68 | P a g e
b) del deletes the values in the dictionary
c) del deletes the entire dictionary
d) del deletes the keys in the dictionary
25. If a is a dictionary with some key-value pairs, what does a.popitem() do?
a) Removes an arbitrary element
b) Removes all the key-value pairs
c) Removes the key-value pair for the key given as an argument
d) Invalid method for dictionary
69 | P a g e
b) An exception is thrown
c) {‘a’:‘b’:‘c’:}
d) {1: ‘a’, 2: ‘b’, 3: ‘c’}
ANSWERS :
1.d 2.b 3.a 4.b 5.c 6.a 7.c 8.b 9.a 10.c 11.b 12.c 13.a 14.b 15.c 16.b
17.d 18.c 19.b 20.d 21.a 22.d 23.c 24.c 25.a 26.a 27.d 28.b 29.c
30.a 31.d 32.a
1.a2.b3.4.5.
70 | P a g e
b) outfile = open(“c:\\scores.txt”, “w”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
6. To read the entire remaining contents of the file as a string from a file object infile, we use
____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)
a) True
b) False
c) None
d) Error
8. To read the next line of the file from a file object infile, we use ____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
9. To read the remaining lines of the file from a file object infile, we use ____________
a) infile.read(2)
71 | P a g e
b) infile.read()
c) infile.readline()
d) infile.readlines()
11. Which are the two built-in functions to read a line of text from standard input, which by default
comes from the keyboard?
a) Raw_input & Input
b) Input & Scan
c) Scan & Scanner
d) Scanner
a) closed
b) softspace
c) rename
d) mode
72 | P a g e
a) tells you the current position within the file
b) tells you the end position within the file
c) tells you the file is opened or not
d) none of the mentioned
a) rename(current_file_name, new_file_name)
b) rename(new_file_name, current_file_name,)
c) rename(()(current_file_name, new_file_name))
d) none of the mentioned
fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name
a) Compilation Error
b) Syntax Error
c) Displays Output
d) None of the mentioned
73 | P a g e
a) truncates the file size
b) deletes the content of the file
c) deletes the file size
d) none of the mentioned.
import sys
sys.stdout.write(' Hello\n')
sys.stdout.write('Python\n')
a) Compilation Error
b) Runtime Error
c) Hello Python
d) Hello
Python
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
fo.flush()
fo.close()
74 | P a g e
a) Compilation Error
b) Runtime Error
c) No Output
d) Flushes the file when closing them
30. In file handling, what does this terms means “r, a”?
a) read, append
b) append, read
c) write, append
d) none of the mentioned
75 | P a g e
36. Which function is used to write a list of string in a file?
a) writeline()
b) writelines()
c) writestatement()
d) writefullline()
39. Which of the following are the modes of both writing and reading in binary format in file?
a) wb+
b) w
c) wb
d) w+
42. How do you get the name of a file from a file object (fp)?
a) fp.name
b) fp.file(name)
c) self.__name__(fp)
d) fp.__name__()
43. Which of the following is not a valid attribute of a file object (fp)?
a) fp.name
b) fp.closed
c) fp.mode
d) fp.size
76 | P a g e
c) fp.close()
d) fp.__close__()
45. How do you get the current position within the file?
a) fp.seek()
b) fp.tell()
c) fp.loc
d) fp.pos
48. How do you change the file position to an offset value from the start?
a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned
77 | P a g e
b) no, finally cannot be used with except
c) no, finally must come before except
d) yes
78 | P a g e
c) an TypeError occurs
d) a ValueError occurs
10. The following Python code will result in an error if the input value is entered as -5.
assert False, 'Spanish'
a) True
b) False
79 | P a g e
l2=[4, 5, 6]
l=itertools.chain(l1, l2)print(next(l1))
a) ‘list’ object is not iterator
b) ‘tuple’ object is not iterator
c) ‘list’ object is iterator
d) ‘tuple’ object is iterator
17. What happens if the file is not found in the following Python code?
a=Falsewhile not a:
try:
f_n = input("Enter file name")
i_f = open(f_n, 'r')
except:
print("Input file not found")
a) No error
b) Assertion error
c) Input output error
d) Name error
20. What will be the output of the following Python code, if the time module has already been
imported?
4 + '3'
a) NameError
b) IndexError
c) ValueError
d) TypeError
80 | P a g e
22. What will be the output of the following Python code if the input entered is 6?
valid = Falsewhile not valid:
try:
n=int(input("Enter a number"))
while n%2==0:
print("Bye")
valid = True
except ValueError:
print("Invalid")
a) Bye (printed once)
b) No output
c) Invalid (printed once)
d) Bye (printed infinite number of times)
29. Which of the following blocks will be executed whether an exception is thrown or not?
a) except
81 | P a g e
b) else
c) finally
d) assert
1.d 2.c 3.b 4.d 5.a 6.d 7.b 8.a 9.b 10.a 11.c 12.b
13.c 14.a 15.b 16.c 17.a 18.c 19.b 20.d 21.b 22.d
23.b 24.a 25.c 26.a 27.a 28.d 29.c
3. Program code making use of a given module is called a ______ of the module.
a) Client
b) Docstring
c) Interface
d) Modularity
4. ______ is a string literal denoted by triple quotes for providing the specifications of certain
program elements.
a) Interface
b) Modularity
c) Client
d) Docstring
82 | P a g e
8. Which of the following isn’t true about main modules?
a) When a python file is directly executed, it is considered main module of a program
b) Main modules may import any number of modules
c) Special name given to main modules is: __main__
d) Other main modules can import main modules
.
9. Which of the following is not a valid namespace?
a) Global namespace
b) Public namespace
c) Built-in namespace
d) Local namespace
10. Which of the following is false about “import modulename” form of import?
a) The namespace of imported module becomes part of importing module
b) This form of import prevents name clash
c) The namespace of imported module becomes available to importing module
d) The identifiers in module are accessed as: modulename.identifier
14. What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the global namespace, then the local namespace and finally the built-in
namespace
b) Python first searches the local namespace, then the global namespace and finally the built-in
namespace
c) Python first searches the built-in namespace, then the global namespace and finally the local
namespace
d) Python first searches the built-in namespace, then the local namespace and finally the global
namespace
83 | P a g e
1.b 2.c 3.a 4.d 5.c 6.b 7.b 8.d 9.b 10.a 11.b 12.c
13.d 14.b
1. _____ represents an entity in the real world with its identity and behaviour.
a) A method
b) An object
c) A class
d) An operator
def display(self):
print(self.a)
obj=test()
obj.display()
a) The program has an error because constructor can’t have default arguments
b) Nothing is displayed
c) “Hello World” is displayed
d) The program has an error display function doesn’t have parameters
x = change(1,2,3)
y = getattr(x, 'a')setattr(x, 'a', y+1)print(x.a)
84 | P a g e
a) 6
b) 7
c) Error
d) 0
def display(self):
print(self.a)
obj=test()
obj.display()
a) Runs normally, doesn’t display anything
b) Displays 0, which is the automatic default value
c) Error as one argument is required while creating the object
d) Error as display function requires additional argument
85 | P a g e
obj.quantity=10
obj.bags=2
print(obj.quantity+len(obj.__dict__))
a) 12
b) 52
c) 13
d) 60
12. The assignment of more than one function to a particular operator is _______
a) Operator over-assignment
b) Operator overriding
c) Operator overloading
d) Operator instance
15. What are the methods which begin and end with two underscore characters called?
a) Special methods
b) In-built methods
c) User-defined methods
d) Additional methods
86 | P a g e
d) Yes, this method of calling is called bounded method call
21. What does print(Test.__name__) display (assuming Test is the name of the class)?
a) ()
b) Exception is thrown
c) Test
d) __main__
ANSWERS :
1.b 2.b 3.c 4.b 5.a 6.b 7.c 8.a 9.c 10.d 11.c 12.c
13.a 14.b 15.a 16.b 17.c 18.c 19.b 20.a 21.c 22.a
87 | P a g e
d) Allows for implementation of elegant software that is well designed and easily modified
88 | P a g e
pass
obj = B()
obj.disp()
a) Invalid syntax for inheritance
b) Error because when object is created, argument must be passed
c) Nothing is printed
d) A disp()
7. When defining a subclass in Python that is meant to serve as a subtype, the subtype Python
keyword is used.
a) True
b) False
8. Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of
code you should write?
a) A.__init__(self)
b) B.__init__(self)
c) A.__init__(B)
d) B.__init__(A)
89 | P a g e
11. What does built-in function type do in context of classes?
a) Determines the object name of any value
b) Determines the class name of any value
c) Determines class description of any value
d) Determines the file name of any value
def two(self):
return 'A'
class B(A):
def two(self):
return 'B'
obj1=A()
obj2=B()print(obj1.two(),obj2.two())
a) A A
b) A B
c) B B
d) An exception is thrown
90 | P a g e
c) Hierarchical inheritance
d) Single-level inheritance
def display(self):
print(self.__i, self.j)class B(A):
def __init__(self):
super().__init__()
self.__i = 2
self.j = 7
c = B()
c.display()
a) 2 7
b) 1 5
c) 1 7
d) 2 5
91 | P a g e
23. What will be the output of the following Python code?
class A:
def __init__(self):
self.__x = 1class B(A):
def display(self):
print(self.__x)def main():
obj = B()
obj.display()
main()
a) 1
b) 0
c) Error, invalid syntax for object declaration
d) Error, private class member can’t be accessed in a subclass
main()
a) 5
b) Error, class member x has two values
c) 3
d) Error, protected class member can’t be accessed in a subclass
View Answer
26. What will be the output of the following Python code?
class A:
def test1(self):
print(" test of A called ")class B(A):
def test(self):
print(" test of B called ")class C(A):
def test(self):
92 | P a g e
print(" test of C called ")class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
a)
test of B called
test of C called
b)
test of C called
test of B called
c) test of B called
d) Error, both the classes from which D derives has same method test()
a) test of B called
test of C called
test of A called
b) test of C called
test of B called
c) test of B called
test of C called
d) Error, all the three classes from which D derives has same method test()
1.a 2.c 3.b 4.c 5.d 6.b 7.b 8.a 9.c 10.d 11.b 12.a 13.c 14.b
15.b 16.a 17.c 18.c 19.c 20.a 21.c 22.a 23.d 24.c 25.a 26.c
27.a
93 | P a g e
UNIT V
2. Only problems that are recursively defined can be solved using recursion.
94 | P a g e
a)True
b) False
4. Fill in the line of the following Python code for calculating the factorial of a number.
def fact(num):
if num == 0:
return 1
else:
return _____________________
a) num*fact(num-1)
b) (num-1)*(num-2)
c) num*(num-1)
d) fact(num)*fact(num-1)
a) 13
b) 7
c) Infinite loop
d) 17
a) 50
95 | P a g e
b) 100
c) 74
d) Infinite loop
10. What happens if the base condition isn’t defined in recursive programs?
a) Program gets into an infinite loop
b) Program runs once
c) Program runs n number of times where n is the argument given to the function
d) An exception is thrown
a) 0 1 2 3
b) An exception is thrown
c) 0 1 1 2 3
d) 0 1 1 2
14. Suppose the first fibonnaci number is 0 and the second is 1. What is the sixth
fibonnaci number?
a) 5
b) 6
c) 7
d) 8
96 | P a g e
15. Which of the following is not a fibonnaci number?
a) 8
b) 21
c) 55
d) 14
17. Which of the following recurrence relations can be used to find the nth fibonacci
number?
a) F(n) = F(n) + F(n – 1)
b) F(n) = F(n) + F(n + 1)
c) F(n) = F(n – 1)
d) F(n) = F(n – 1) + F(n – 2)
18. How many times will the function fibo() be called when the following code is executed?
int fibo(int n){
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);}int main(){
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;}
a) 5
b) 6
c) 8
d) 9\
19. What is the output of the following code?
int fibo(int n){
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);}int main(){
int n = 10;
int ans = fibo(n);
printf("%d",ans);
return 0;}
a) 21
b) 34
c) 55
d) 13
97 | P a g e
20. What is the output of the following code?
int fibo(int n){
if(n == 1)
return 0;
else if(n == 2)
return 1;
return fibo(n - 1) + fibo(n - 2);}int main(){
int n = 5;
int ans = fibo(n);
printf("%d",ans);
return 0;}
a) 1
b) 2
c) 3
d) 5
23. The time complexity of the solution tower of hanoi problem using recursion is _________
a) O(n2)
b) O(2n)
c) O(n log n)
d) O(n)
24. Recurrence equation formed for the tower of hanoi problem is given by _________
a) T(n) = 2T(n-1)+n
b) T(n) = 2T(n/2)+c
c) T(n) = 2T(n-1)+c
d) T(n) = 2T(n/2)+n
25. Minimum number of moves required to solve a tower of hanoi problem with n disks is
__________
a) 2n
b) 2n-1
c) n2
d) n2-1
98 | P a g e
d) O(n log n)
29. Minimum time required to solve tower of hanoi puzzle with 4 disks assuming one
move takes 2 seconds, will be __________
a) 15 seconds
b) 30 seconds
c) 16 seconds
d) 32 seconds
ANSWERS :
1.b 2.b 3.c 4.a 5.d 6.d 7.d 8.b 9.b 10.a 11.c 12.b
13.d 14.a 15.d 16.d 17.d 18.d 19.b 20.c 21.a 22.c
23.b 24.c 25.b 26.b 27.d 28.a 29.b
99 | P a g e
d) O(1)
4. What is the best case and worst case complexity of ordered linear search?
a) O(nlogn), O(logn)
b) O(logn), O(nlogn)
c) O(n), O(1)
d) O(1), O(n)
10. The array is as follows: 1,2,3,6,8,10. At what time the element 6 is found? (By
100 | P a g e
using linear search(recursive) algorithm)
a) 4th call
b) 3rd call
c) 6th call
d) 5th call
11. The array is as follows: 1,2,3,6,8,10. Given that the number 17 is to be searched.
At which call it tells that there’s no such element? (By using linear search(recursive)
algorithm)
a) 7th call
b) 9th call
c) 17th call
d) The function calls itself infinite number of times
13. Can linear search recursive algorithm and binary search recursive algorithm be
performed on an unordered list?
a) Binary search can’t be used
b) Linear search can’t be used
c) Both cannot be used
d) Both can be used
14. What is the recurrence relation for the linear search recursive algorithm?
a) T(n-2)+c
b) 2T(n-1)+c
c) T(n-1)+c
d) T(n+1)+c
16. Given an input arr = {2,5,7,99,899}; key = 899; What is the level of recursion?
a) 5
b) 2
c) 3
d) 4
101 | P a g e
17. Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid
values(corresponding array elements) in the first and second levels of recursion?
a) 90 and 99
b) 90 and 94
c) 89 and 99
d) 89 and 94
18. What is the worst case complexity of binary search using recursion?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
19. What is the average case time complexity of binary search using recursion?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
22. Given an array arr = {5,6,77,88,99} and key = 88; How many iterations are done
until the element is found?
a) 1
b) 3
c) 4
d) 2
23. Given an array arr = {45,77,89,90,94,99,100} and key = 100; What are the mid
values(corresponding array elements) generated in the first and second iterations?
a) 90 and 99
b) 90 and 100
c) 89 and 94
d) 94 and 99
102 | P a g e
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
ANSWERS :
1.d 2.d 3.c 4.d 5.b 6.c 7.a 8.a 9.a 10.a 11.a 12.a 13.a 14.c
15.b 16.c 17.a 18.b 19.b 20.d 21.b 22.d 23.a 24.b
103 | P a g e
c) It can be used for small keys
d) It takes linear time to sort the elements
7. The given array is arr = {3,4,5,2,1}. The number of iterations in bubble sort and
selection sort respectively are,
a) 5 and 4
b) 4 and 5
c) 2 and 4
d) 2 and 5
8. The given array is arr = {1,2,3,4,5}. (bubble sort is implemented with a flag
variable)The number of iterations in selection sort and bubble sort respectively are,
a) 5 and 4
b) 1 and 4
c) 0 and 4
d) 4 and 1
10. Merge sort uses which of the following technique to implement sorting?
a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming
104 | P a g e
b) O(n2)
c) O(n2log n)
d) O(n log n2)
15. Which of the following method is used for sorting in merge sort?
a) merging
b) partitioning
c) selection
d) exchanging
16. What will be the best case time complexity of merge sort?
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
18. Choose the incorrect statement about merge sort from the following?
a) it is a comparison based sort
b) it is an adaptive algorithm
c) it is not an in place algorithm
d) it is stable algorithm
21. Which of the following stable sorting algorithm takes the least time when applied
to an almost sorted array?
a) Quick sort
b) Insertion sort
c) Selection sort
d) Merge sort
105 | P a g e
22. Merge sort is preferred for arrays over linked lists.
a) true
b) false
23. Which of the following sorting algorithm makes use of merge sort?
a) tim sort
b) intro sort
c) bogo sort
d) quick sort
24. Which of the following sorting algorithm does not use recursion?
a) quick sort
b) merge sort
c) heap sort
d) bottom up merge sort
ANSWERS :
1.a 2.c 3.d 4.a 5.d 6.b 7.a 8.d 9.d 10.c
11.a 12.c 13.a 14.a 15.a 16.a 17.a 18.b 19.a
20.a 21.d 22.b 23.a 24.d
106 | P a g e
By OnlineInterviewQuestions.com
Python MCQ Quiz
A. yes
B. no
A. UPPER CASE
B. lower case
C. Capitalized
D. None of the mentioned
Q4. Mathematical operations can be performed on a string. State whether true or false -
A. False
B. True
Q5. Which one of the following has the highest precedence in the expression?
A. Addition
B. Multiplication
C. Exponential
D. Parentheses
A. float
B. bool
C. dict
D. int
Q7. What is the output of the following? print("Hello {0!r} and {0!s}".format('foo', 'bin'))
A. String
B. Numbers
C. Slice
D. List
Q9. Which Of The Following Keywords Mark The Beginning Of The Class Definition?
A. return
B. class
C. def
D. All of the above
A. Yes
B. no
Q12. Python allows string slicing. What is the output of below code: s='cppbuzz chicago'
print(s[3:5])
A. buzzc
B. pbuzz
C. bu
D. None of these
Q13. class test: def __init__(self): print "Hello World" def __init__(self): print "Bye
World" obj=test()
A. Bye World
B. Hello World
C. Compilation Error
D. Ambiguity
A. list
B. bool
C. int
D. str
A. 32 characters
B. 63 characters
C. 79 characters
D. 31 Characters
Q17. Which one of the following is not a python's predefined data type?
A. List
B. Dictionary
C. Tuple
D. Class
A. 13
B. 15
C. 2
D. None of these
Q19. 19 % 2 in python
A. 2
B. 17
D. None of these
A. /
B. +
C. ()
D. -
Q21. Is Tuple mutable?
A. yes
B. no
23. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
a) True
b) False
c) None
d) Error
Answer: a
Explanation: In can be used to check if the key is int dictionary.
24. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 == d2
a) True
b) False
c) None
d) Error
Answer: b
Explanation: If d2 was initialized as d2 = d1 the answer would be true.
25. What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a) True
b) False
c) Error
d) None
Answer: c
Explanation: Arithmetic > operator cannot be used with dictionaries.
26. Which of the following is a Python tuple?
a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {}
Answer: b
Explanation: Tuples are represented with round brackets.
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
Answer: c
Explanation: Slicing in tuples takes place just as it does in strings.
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
Answer: c
Explanation: Slicing in tuples takes place just as it does in strings.
a) [2, 3, 9]
b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8]
d) (1, 4, 8)
Answer: c
Explanation: Execute in the shell to verify.
a) 40
b) 45
c) “john”
d) “peter”
Answer: a
Explanation: Execute in the shell to verify.
a) (1, 2, 1, 2)
b) [1, 2, 1, 2]
c) (1, 1, 2, 2)
d) [1, 1, 2, 2]
Answer: a
Explanation: * operator concatenates tuple.
34. Which of the following is not the correct syntax for creating a set?
a) set([[1,2],[3,4]])
b) set([1,2,2,3,4])
c) set((1,2,3,4))
d) {1,2,3,4}
Answer: a
Explanation: The argument given for the set must be an iterable.
Answer: (b) C
Explanation: Python is written in C programming language, and it is also called CPython.
Q. Which one of the following is the correct extension of the Python file?
a. .py
b. .python
c. .p
d. None of these
Answer: (c) #
Explanation: "#" character is used in Python to make a single-line comment.
Q. Which of the following statements is correct regarding the object-oriented programming concept in
Python?
a. Classes are real-world entities while objects are not real
b. Objects are real-world entities while classes are not real
c. Both objects and classes are real-world entities
d. All of the above
Answer: (b) Objects are real-world entities while classes are not real
Explanation: None
Q. Why does the name of local variables start with an underscore discouraged?
a. To identify the variable
b. It confuses the interpreter
c. It indicates a private variable of a class
d. None of these
Q. Which of the following statements is correct for variable names in Python language?
a. All variable names must begin with an underscore.
b. Unlimited length
c. The variable name length is a maximum of 2.
d. All of the above
Q. Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses
Answer: (d) 5
Explanation: The round function is a built-in function in the Python language that round-off the
value (like 3.85 is 4), so the output of this function will be 5.
Q. Which one of the following syntaxes is the correct syntax to read from a simple text file stored in
''d:\java.txt''?
a. Infile = open(''d:\\java.txt'', ''r'')
b. Infile = open(file=''d:\\\java.txt'', ''r'')
c. Infile = open(''d:\java.txt'',''r'')
d. Infile = open.file(''d:\\java.txt'',''r'')
Answer: (a) t
Explanation: The correct output of this program is "t" because -1 corresponds to the last index.
Answer: (a) 33
Explanation: A, B and C are hexadecimal integers with values 10, 11 and 12 respectively, so the sum
of A, B and C is 33.
Answer: (b) 1 2 3 4 5 6
Explanation: None
Answer: (c) 0 1 2
Explanation: None
Answer: (c) 0 1 2 0
Explanation: None
Answer: (b) 0 1 2
Explanation: None
Q. Study the following program:
1. d = {0, 1, 2}
2. for x in d:
3. print(x)
What will be the output of this statement?
a. {0, 1, 2} {0, 1, 2} {0, 1, 2}
b. 0 1 2
c. Syntax_Error
d. None of these above
Answer: (b) 0 1 2
Explanation: None
Q. Which of the following option is not a core data type in the python language?
a. Dictionary
b. Lists
c. Class
d. All of the above
Q. What error will occur when you execute the following code?
MANGO = APPLE
a. NameError
b. SyntaxError
c. TypeError
d. ValueError
NUMPY :
Question:
Correct syntax of the reshape() function in Numpy array python is -
1.array.reshape(shape)
2.reshape(shape,array)
3.reshape(array,shape)
4.reshape(shape)
Answer:3
Question:
How we can change the shape of the Numpy array in python?
1.By Shape()
2.By reshape()
3.By ord()
4.By change()
Answer:2
Question:
How we can convert the Numpy array to the list in python?
1.list(array)
2.list.array
3.array.list
4.None of the above
Answer:1
Question:
How we can find the type of numpy array in python ?
1.dtype
2.type
3.typei
4.itype
Answer:1
Question:
How we install Numpy in the system ?
1.install numpy
2.pip install python numpy
3.pip install numpy
4.pip install numpy python
Answer:3
Question:
It is possible to convert the Numpy array to list in python ?
1.Yes
2.No
3.Sometimes
4.None of the above
Answer:1
Question:
Minimum number of argument to pass in full() function in Numpy array ?
1.0
2.1
3.2
4.3
Answer:3
Question:
Numpy in the Python provides the
1.Function
2.Lambda function
3.Type casting
4.Array
Answer:4
Question:
Numpy.array(list), what it does ?
Question:
Shape() function in Numpy array is used to
Question:
What is the use of the size attribute in Numpy array in python ?
Question:
what is the use of the zeros() function in Numpy array in python ?
Question:
Which of the following argument we need to pass in reshape() function?
1.Array
2.Shape
3.only array
4.Both array and shape
Answer:4
Question:
Which of the following counts the number of elements in Numpy array ?
1.count()
2.return()
3.shape()
4.size()
Answer:4
Question:
Which of the following find the maximum number in the Numpy array ?
1.max(array)
2.array.max()
3.array(max)
4.None of the above
Answer:2
Question:
Which of the following is correct way to import the Numpy module in your program ?
1.import numpy
2.import numpy as np
3.from numpy import *
4.All of the above
Answer:4
Question:
Which of the following is not valid to import the numpy module ?
1.import numpy as np
2.import numpy as n
3.import numpy as p
4.None of the above
Answer:4
Question:
Which of the following is the essential argument to pass in full() function of Numpy array ?
1.shape
2.value
3.Both of the above
4.None of the above
Answer:3
Question:
Which of the following is used to convert the list data type to the Numpy array ?
1.array(list)
2.array.list
3.Numpy.array(list)
4.None of the above
Answer:3
Question:
Which of the following keyword is used to access the numpy module in python ?
1.access
2.import
3.fetch
4.from
Answer:2
import pandas as pd
s = pd.Series([1,2,3,4,5],index = ['a','b','c','d','e'])
print s['a']
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : A
Explanation: A pandas Series can be created using the following constructor : pandas.Series( data,
index, dtype, copy)
Q. What will be syntax for pandas dataframe?
A. minor_axis
B. major_axis
C. items
D. None of the above
View Answer
Ans : B
A. a python dict
B. an ndarray
C. a scalar value
D. All of the above
View Answer
Ans : D
Q. The ________ project builds on top of pandas and matplotlib to provide easy plotting of data.
A. yhat
B. Seaborn
C. Vincent
D. Pychart
View Answer
Ans : B
Explanation: ndim : Returns the number of dimensions of the underlying data, by definition 1
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(2))
print s.size
A. 0
B. 1
C. 2
D. 3
View Answer
Ans : C
A. The integer format tracks only the locations and sizes of blocks of data.
B. Pandas follow the NumPy convention of raising an error when you try to convert something to a
bool.
C. Two kinds of SparseIndex are implemented
D. The integer format keeps an arrays of all of the locations where the data are not equal to the fill
value
View Answer
Ans : A
Explanation: The block format tracks only the locations and sizes of blocks of data.
A. science library
B. source library
C. significant library
D. scientific library
Ans : D
Explanation: SciPy, a scientific library for Python is an open source, BSD-licensed library for
mathematics, science and engineering.
A. scipy.cluster
B. scipy.source
C. scipy.interpolate
D. scipy.signal
Ans : B
A. By default, all the NumPy functions have been available through the SciPy namespace
B. There is no need to import the NumPy functions explicitly, when SciPy is imported.
C. SciPy is built on top of NumPy arrays
D. All of the above
Ans : D
import numpy as np
print np.linspace(1., 4., 6)
A. array([ 1. , 2.2, 2.8, 3.4, 4. ])
B. array([ 1. , 1.6, 2.8, 3.4, 4. ])
C. array([ 1. , 1.6, 2.2, 2.8, 3.4, 4. ])
D. array([ 1. , 1.6, 2.2, 2.8, 4. ])
Ans : C
Explanation: The above program will generate the following output : array([ 1. , 1.6, 2.2, 2.8, 3.4, 4. ])
A. import scipy.constants
B. from scipy.constants
C. import scipy.constants.package
D. from scipy.constants.package
Ans : B
A. G
B. e
C. R
D. k
Ans : D
Explanation: The above program will generate the following output : array([ 2., -2., 9.])
A. determinant()
B. SciPy.determinant()
C. det()
D. SciPy.det()
Ans : C
A. scipy.linalg also has some other advanced functions that are not in numpy.linalg
B. SciPy version might be faster depending on how NumPy was installed.
C. Both A and B
D. None of the above
Ans : D
Q. What relation is consider between Eigen value (lambda), square matrix (A) and Eign vector(v)?
A. Av = lambda*v
B. Av =Constant * lambda*v
C. Av =10 * lambda*v
D. Av != lambda*v
Ans : A
Explanation: We can find the Eigen values (lambda) and the corresponding Eigen vectors (v) of a
square matrix (A) by considering the following relation.
Q. p → 0q is not a?
A. hack clause
B. horn clause
C. structural clause
D. system clause
Ans : B
A. STACK(A,B)
B. LIST(A,B)
C. QUEUE(A,B)
D. ARRAY(A,B)
Ans : A
Explanation: The action 'STACK(A,B)' of a robot arm specify to Place block A on block B.
A. bottow-up parser
B. top parser
C. top-down parser
D. bottom parser
Ans : C
Explanation: A top-down parser begins by hypothesizing a sentence (the symbol S) and successively
predicting lower level constituents until individual preterminal symbols are written.
Q. A model of language consists of the categories which does not include ________.
A. System Unit
B. structural units.
C. data units
D. empirical units
Ans : B
Explanation: A model of language consists of the categories which does not include structural units.
A. Introduction
B. Analogy
C. Deduction
D. Memorization
Ans : A
Q. The model will be trained with data in one single batch is known as ?
A. Batch learning
B. Offline learning
C. Both A and B
D. None of the above
Ans : C
Explanation: we have end-to-end Machine Learning systems in which we need to train the model in
one go by using whole available training data. Such kind of learning method or algorithm is called
Batch or Offline learning.
Explanation: The following are various ML methods based on some broad categories : Based on
human supervision, Unsupervised Learning, Semi-supervised Learning and Reinforcement Learning
Q. In Model based learning methods, an iterative process takes place on the ML models that are built
based on various model parameters, called ?
A. mini-batches
B. optimizedparameters
C. hyperparameters
D. superparameters
Ans : C
Explanation: In Model based learning methods, an iterative process takes place on the ML models that
are built based on various model parameters, called hyperparameters.
Q. Which of the following is a widely used and effective machine learning algorithm based on the
idea of bagging?
A. Decision Tree
B. Regression
C. Classification
D. Random Forest
Ans : D
Explanation: The Radom Forest algorithm builds an ensemble of Decision Trees, mostly trained with
the bagging method.
Q. To find the minimum or the maximum of a function, we set the gradient to zero because:
Explanation: The gradient of a multivariable function at a maximum point will be the zero vector of
the function, which is the single greatest value that the function can achieve.
A. Factor analysis
B. Decision trees are robust to outliers
C. Decision trees are prone to be overfit
D. None of the above
Ans : C
Explanation: Allowing a decision tree to split to a granular degree makes decision trees prone to
learning every point extremely well to the point of perfect classification that is overfitting.
Explanation: All of the above techniques are different ways of imputing the missing values.
Q. When performing regression or classification, which of the following is the correct way to
preprocess the data?
Explanation: You need to always normalize the data first. If not, PCA or other techniques that are
used to reduce dimensions will give different results.
A. Using too large a value of lambda can cause your hypothesis to underfit the data.
B. Using too large a value of lambda can cause your hypothesis to overfit the data
C. Using a very large value of lambda cannot hurt the performance of your hypothesis.
D. None of the above
Ans : D
Explanation: A large value results in a large regularization penalty and therefore, a strong preference
for simpler models, which can underfit the data.
Q. Which of the following techniques can not be used for normalization in text mining?
A. Stemming
B. Lemmatization
C. Stop Word Removal
D. None of the above
Ans : C
Q. In which of the following cases will K-means clustering fail to give good results?
1) Data points with outliers
2) Data points with different densities
3) Data points with nonconvex shapes
A. 1 and 2
B. 2 and 3
C. 1 and 3
D. All of the above
Ans : D
Explanation: K-means clustering algorithm fails to give good results when the data contains outliers,
the density spread of data points across the data space is different, and the data points follow
nonconvex shapes.
Q. Which of the following is a reasonable way to select the number of principal components "k"?
A. Choose k to be the smallest value so that at least 99% of the varinace is retained.
B. Choose k to be 99% of m (k = 0.99*m, rounded to the nearest integer).
C. Choose k to be the largest value so that 99% of the variance is retained.
D. Use the elbow method.
Ans : A
Explanation: This will maintain the structure of the data and also reduce its dimension.
Explanation: Sentence parsers analyze a sentence and automatically build a syntax tree.
MCQ
CLASS TEST – I
a) yes
b) no
c) machine dependent
a) 31 characters
b) 63 characters
c) 79 characters
a) _a = 1
b) __a = 1
c) __str__ = 1
a) my_string_1
b) 1st_string
c) foo
d) _
Page No 1
5. Why are local variable names beginning with an underscore discouraged?
a) eval
b) assert
c) nonlocal
d) pass
a) lower case
b) UPPER CASE
c) Capitalized
a) unlimited length
c) underscore and ampersand are the only two special characters allowed
a) abc = 1,000,000
Page No 2
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
a) __init__
b) in
c) it
d) on
Page No 3
MCQ
CLASS TEST – II
Page No 4
5. Mathematical operations can be performed on a string. State whether true or
false.
a) True
b) False
9. The expression Int(x) implies that the variable x is converted to integer. State
whether true or false.
a) True
b) False
10. Which one of the following have the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
Page No 5
MCQ
2. Given a function that does not return any value, What value is thrown by default
when executed in shell.
a) int
b) bool
c) void
d) None
3. Following set of commands are executed in shell, what will be the output?
>>>str="hello"
>>>str[:2]
>>>
a) he
b) lo
c) olleh
d) hello
a) round(45.8)
b) round(6352.898,2,5)
c) round()
Page No 6
d) round(7463.123,2,1)
a) int
b) float
c) bool
d) dict
>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
def example(a):
a = a + '2'
a = a*2
return a
Page No 7
>>>example("hello")
a) indentation Error
c) hello2
d) hello2hello2
a) list
b) dictionary
c) array
d) tuple
10. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
c) ‘3\’
d) ”’That’s okay”’
12. What is the average value of the code that is executed below ?
>>>grade1 = 80
Page No 8
>>>grade2 = 90
a) 85
b) 85.1
c) 95
d) 95.1
hello-how-are-you
c) print(‘hello-‘ + ‘how-are-you’)
a) int
b) bool
c) float
d) None
a) True
b) False
c) Machine dependent
d) Error
a) k = 2 + 3j
Page No 9
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J
a) Boolean
b) Integer
c) Float
d) Complex
a) -5
b) -4
c) -3
d) +3
a) +5
b) -11
c) +11
d) -5
a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964
Page No 10
MCQ
CLASS TEST IV
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
a) [‘ab’, ‘cd’].
b) [‘AB’, ‘CD’].
c) [None, None].
x = ['ab', 'cd']
for i in x:
x.append(i.upper())
print(x)
a) [‘AB’, ‘CD’].
c) [‘ab’, ‘cd’].
i=1
Page No 11
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2
b) 1 2 3
c) error
i=1
while True:
if i%0O7 == 0:
break
print(i)
i += 1
a) 1 2 3 4 5 6
b) 1 2 3 4 5 6 7
c) error
i=5
while True:
if i%0O11 == 0:
Page No 12
break
print(i)
i += 1
a) 5 6 7 8 9 10
b) 5 6 7 8
c) 5 6
d) error
i=5
while True:
if i%0O9 == 0:
break
print(i)
i += 1
a) 5 6 7 8
b) 5 6 7 8 9
c) 5 6 7 8 9 10 11 12 13 14 15 ….
d) error
i=1
while True:
if i%2 == 0:
break
print(i)
i += 2
a) 1
Page No 13
b) 1 2
c) 1 2 3 4 5 6 …
d) 1 3 5 7 9 11 …
i=2
while True:
if i%3 == 0:
break
print(i)
i += 2
a) 2 4 6 8 10 …
b) 2 4
c) 2 3
d) error
i=1
while False:
if i%2 == 0:
break
print(i)
i += 2
a) 1
b) 1 3 5 7 …
c) 1 2 3 4 …
Page No 14
10. What is the output of the following?
True = False
while True:
print(True)
break
a) True
b) False
c) None
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) 0 1 2 0
b) 0 1 2
c) error
i=0
while i < 3:
Page No 15
print(i)
i += 1
else:
print(0)
a) 0 1 2 3 0
b) 0 1 2 0
c) 0 1 2
d) error
x = "abcdef"
while i in x:
a) a b c d e f
b) abcdef
c) i i i i i i …
d) error
x = "abcdef"
i = "i"
while i in x:
a) no output
b) i i i i i i …
c) a b c d e f
d) abcdef
Page No 16
15. What is the output of the following?
x = 'abcd'
for i in x:
print(i.upper())
a) a b c d
b) A B C D
c) a B C D
d) error
x = 'abcd'
for i in range(len(x)):
i.upper()
print (x)
a) a b c d
b) 0 1 2 3
c) error
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)
Page No 17
a) a
c) a a a a
x = 'abcd'
for i in range(len(x)):
print(x)
x = 'a'
a) a
c) a a a a
x = 123
for i in x:
print(i)
a) 1 2 3
b) 123
c) error
for i in d:
print(i)
Page No 18
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
Answer 1: a
Explanation: The function upper() does not modify a string in place, it returns a new
string which isn’t being stored anywhere
Answer 2: d
Explanation: The loop does not terminate as new elements are being added to the
list in each iteration.
Answer 3: c
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.
Answer 4: a
Explanation: Control exits the loop when i become
Answer 5: b
Explanation: 0O11 is an octal number.
Answer6: d
Explanation: 9 isn’t allowed in an octal number.
Answer 7: d
Explanation: The loop does not terminate since i is never an even number.
Answer 8: b
Explanation: The numbers 2 and 4 are printed. The next value of i is 6 which is
divisible by 3 and hence control exits the loop
Answer 9: d
Explanation: Control does not enter the loop because of False..
Answer 10 : d
Explanation: SyntaxError, True is a keyword and it’s value cannot be changed.
Answer 11: b
Explanation: The else part is not executed if control breaks out of the loop.
Answer 12: b
Explanation: The else part is executed when the condition in the while statement is
false.
Answer 13: d
Explanation: NameError, i is not defined.
Page No 19
Answer 14: a
Explanation: “i” is not in “abcdef”.
Answer 15: b
Explanation: The instance of the string returned by upper() is being printed.
Answe 16 : c
Explanation: Objects of type int have no attribute upper().
Answer 17: c
Explanation: range() is computed only at the time of entering the loop.
Answer 18 : d
Explanation: abcd a a a is the output as x is modified only after ‘abcd’ has been
printed once.
Answer 19: c
Explanation: Objects of type int are not iterable.
Answer 20: a
Explanation: Loops over the keys of the dictionary.
Page No 20
MCQ
CHAPTER V
STRING MANIPULATION
CLASS TEST V
>>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase
Page No 21
4. What is the output when following code is executed ?
>>> str1[-1:]
a) olleh
b) hello
c) h
d) o
a) +
b) *
c) –
>>>print r"\nhello"
The output is
b) \nhello
d) error
>>>print('new' 'line')
a) Error
Page No 22
c) newline
d) new line
>>> print(‘x\97\x98’)
a) Error
b) 97
98
c) x\97
d) \x97\x98
>>>str1="helloworld"
>>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
a) 0xA0xB0xC
b) Error
c) 0x22
d) 33
print("xyyzxyzxzxyy".count('yy'))
a) 2
b) 0
Page No 23
c) error
print("xyyzxyzxzxyy".count('yy', 1))
a) 2
b) 0
c) 1
print("xyyzxyzxzxyy".count('yy', 2))
a) 2
b) 0
c) 1
print("xyyzxyzxzxyy".count('xyy', 0, 100))
a) 2
b) 0
c) 1
d) error
print("xyyzxyzxzxyy".count('xyy', 2, 11))
a) 2
b) 0
c) 1
d) error
Page No 24
print("xyyzxyzxzxyy".count('xyy', -10, -1))
a) 2
b) 0
c) 1
d) error
1 Answer: d
2 Answer: c
3 Answer: b
4 Answer: d
5 Answer: c
6 Answer: b
7 Answer: c
8 Answer: c
9 Answer: a
10 Answer: d
11 Answer: a
12 Answer: a
13 Answer: c
14 Answer: a
15 Answer: b
16 Answer: b
Page No 25
MCQ
CLASS TEST VI
a) Controlling
b) Tracing
c) Stepping
d) Testing
a) True
b) False
a) GDB
b) GNB
c) FDB
d) FNB
a) he
b) h
c) assist
d) assistant
Page No 26
b) Describes all the commands
a) run
b) exit
c) execute
d) e
7. Which of the following does not affects the execution of the program?
a) Arguments
b) Environment
c) Control
d) I/o
c) no change
a) Identifying
b) Isolating
c) Test
d) Fixing
Page No 27
10. run > outfile command is used to _________
Page No 28
MCQ
a) Error Free
b) Debug
c) Syntax Error
d) Exception
Page No 29
7. Suppose list1 is [1, 5, 9], what is sum(list1) ?
a) 1
b) 9
c) 15
d) Error
9. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], which of the following is correct syntax for
slicing operation?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
d) all of the mentioned
10. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
a) Error
b) None
c) 25
d) 2
11. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ?
a) [2, 33, 222, 14].
b) Error
c) 25
d) [25, 14, 222, 33, 2].
>>>print(names[-1][-1])
a) A
b) Daman
c) Error
d) n
Page No 30
13. What is the output when following code is executed ?
names2 = names1
names3 = names1[:]
names2[0] = 'Alice'
names3[1] = 'Bob'
sum = 0
if ls[0] == 'Alice':
sum += 1
if ls[1] == 'Bob':
sum += 10
print sum
a) 11
b) 12
c) 21
d) 22
a) [2, 6, 4].
b) [1, 3, 2, 1, 3].
c) [1, 3, 2, 1, 3, 2] .
D) [1, 3, 2, 3, 2, 1].
a) [0, 1, 2, 3].
b) [0, 1, 2, 3, 4].
Page No 31
d) [0.0, 0.5, 1.0, 1.5, 2.0].
>>>list2 = [11, 2, 2]
a) True
b) False
c) Error
d) None
a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)
a) list1.insert(3, 5)
b) list1.insert(2, 5)
c) list1.add(3, 5)
d) list1.append(3, 5)
a) list1.remove(“hello”)
b) list1.remove(hello)
c) list1.removeAll(“hello”)
d) list1.removeOne(“hello”)
Page No 32
20. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?
a) 0
b) 1
c) 4
d) 2
Answers
1 – b 2 – d, 3-a,4-a,5-c,6-d,7-c,8c,9-d,10-c,11-a,12-d,13-b,14-c,15-c,16-b,17-b,18-
a,19-a,20-d
Page No 33
MCQ
a) [1, 2, 3].
b) (1, 2, 3)
c) {1, 2, 3}
d) {}
a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
>>>t=(1,2,4,3)
>>>t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
>>>t=(1,2,4,3)
>>>t[1:-1]
Page No 34
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
>>>t = (1, 2, 4, 3, 8, 9)
a) [2, 3, 9].
b) [1, 2, 4, 3, 8, 9].
c) [1, 4, 8].
d) (1, 4, 8)
d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
>>>t = (1, 2)
>>>2 * t
a) (1, 2, 1, 2)
b) [1, 2, 1, 2].
c) (1, 1, 2, 2)
d) [1, 1, 2, 2].
Page No 35
8. What will be the output?
>>>t1 = (1, 2, 4, 3)
>>>t2 = (1, 2, 3, 4)
>>>t1 < t2
a) True
b) False
c) Error
d) None
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
a) 1
b) 2
c) 5
d) Error
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
Page No 36
a) 30
b) 24
c) 33
d) 12
a) Tuple
b) Integer
c) List
b) [2,3].
c) (2,3,4)
d) (2,3)
>>> a=(1,2,(4,5))
>>> b=(1,2,(3,4))
>>> a<b
a) False
b) True
d) Error, < operator is valid for tuples but not if there are sub-tuples
14. What is the output of the following piece of code when executed in Python
shell?
>>> a=("Check")*3
Page No 37
>>> a
a) (‘Check’,’Check’,’Check’)
c) (‘CheckCheckCheck’)
d) Syntax error
>>> a=(1,2,3,4)
>>> del(a[2])
a) Now, a=(1,2,4)
b) Now, a=(1,3,4)
c) Now a=(3,4)
>>> a=(2,3,4)
>>> sum(a,3)
c) 12
d) 9
>>> a=(1,2,3,4)
>>> del a
Page No 38
d) No, invalid syntax for del method
a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type
>>> a=(0,1,2,3,4)
>>> b=slice(0,2)
>>> a[b]
b) [0,2].
c) (0,1)
d) (0,2)
>>> a=(1,2,3)
>>> b=('A','B','C')
>>> c=zip(a,b)
Answers
1 – b 2 – b, 3-c,4-c,5-c,6-a,7-a,8-b,9-d,10-c,11-b,12-d,13-a,14-c,15-d,16-c,17-c,18-
b,19-c,20-a
Page No 39
MCQ
CHAPTER IX - DICTIONARIES
CLASS TEST IX
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
2. Read the code shown below carefully and pick out the keys?
d = {"john":40, "peter":45}
c) 40 and 45
d) d = (40:”john”, 45:”peter”)
d = {"john":40, "peter":45}
"john" in d
a) True
b) False
c) None
d) Error
d1 = {"john":40, "peter":45}
Page No 40
d2 = {"john":466, "peter":45}
d1 == d2
a) True
b) False
c) None
d) Error
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a) True
b) False
c) Error
d) None
d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
7. Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command
do we use
a) d.delete(“john”:40)
b) d.delete(“john”)
Page No 41
c) del d[“john”].
d) del d(“john”:40)
a) d.size()
b) len(d)
c) size(d)
d) d.len()
d = {"john":40, "peter":45}
print(list(d.keys()))
a) [“john”, “peter”].
b) [“john”:40, “peter”:45].
c) (“john”, “peter”)
d) (“john”:40, “peter”:45)
a) Since “susan” is not a value in the set, Python raises a KeyError exception
c) Since “susan” is not a key in the set, Python raises a KeyError exception
d) Since “susan” is not a key in the set, Python raises a syntax error
Page No 42
d) Dictionaries are mutable
b) dict([[1,”A”],[2,”B”]])
c) {1,”A”,2”B”}
d) {}
a={1:"A",2:"B",3:"C"}
print(i,j,end=" ")
a) 1A2B3C
b) 123
c) ABC
a={1:"A",2:"B",3:"C"}
print(a.get(1,4))
a) 1
b) A
c) 4
a={1:"A",2:"B",3:"C"}
print(a.get(5,4))
Page No 43
a) Error, invalid syntax
b) A
c) 5
d) 4
a={1:"A",2:"B",3:"C"}
print(a.setdefault(3))
b) C
c) {1: 3, 2: 3, 3: 3}
a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)
b) None.
c) Error.
d) [1,3,6,10].
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)
Page No 44
b) Method update() doesn’t exist for dictionaries
a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)
d) “None” is printed
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
a) None
d) {}
Answers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
D B A B C A C B A C B C A B D B A C B D
Page No 45
MCQ
CLASS TEST X
a) Insertion sort
b) Selection sort
c) Bubble sort
d) Merge sort
ANSWER: B
a) Merge sort
b) Typical in-place quick sort
c) Heap sort
d) Selection sort
ANSWER: A
a) Selection sort
b) Heap sort
c) Quick sort
d) Merge sort
ANSWER: D
4. If the given input array is sorted or nearly sorted, which of the following
algorithm gives the best performance?
a) Insertion sort
b) Selection sort
c) Quick sort
d) Merge sort
ANSWER: A
Page No 46
5. Which of the following algorithm pays the least attention to the ordering of
the elements in the input list?
a) Insertion sort
b) Selection sort
c) Quick sort
d) None
ANSWER: B
a) Insertion sort
b) Selection sort
c) Heap sort
d) None
ANSWER: B
7. Which of the following algorithms has lowest worst case time complexity?
a) Insertion sort
b) Selection sort
c) Quick sort
d) Heap sort
ANSWER: D
a) Counting sort
b) Radix sort
c) Bucket sort
d) None
ANSWER: B
Page No 47
9. Which of the following sorting algorithm has the running time that is least
dependant on the initial ordering of the input?
a) Insertion sort
b) Quick sort
c) Merge sort
d) Selection sort
ANSWER: D
10. Which of the following algorithm design technique is used in the quick sort
algorithm?
a) Dynamic programming
b) Backtracking
c) Divide-and-conquer
d) Greedy method
ANSWER: C
a) Divide-and-conquer
b) Backtracking
c) Heuristic approach
d) Greedy approach
ANSWER: A
Page No 48
MCQ
5. Where are data and programme stored when the processor uses them?
Page No 49
8. Which of the following is a storage device?
c. 680 MB d. 680 GB
14. Human beings are referred to as Homosapinens, which device is called Sillico
Sapiens?
a. Monitor b. Hardware
c. Robot d. Computer
Page No 50
15. Which of the following are input devices?
16. 1 Byte =?
19. Data becomes ................ when it is presented in a format that people can
understand and use
Page No 51
MCQ
a) 1 b) 2 c) 7 d) 8
4 110+110=…………
9. 110100112= ?16
10 25?10= ?2__________
Page No 52
MCQ
Page No 53
MCQ
CHAPTER XV
CLASS TEST XV
1. What is translator?
2. List the compilation steps
3. What is Analysis or Front end phase?
4. What is Synthesis or Back end phase?
5. What is Linking?
6. What is Loader?
7. What is interpreter?
8. What is Cloud Computing?
9. What is public cloud?
10. What is private cloud?
Page No 54
MCQ
Ans: A
Ans: A
Page No 55
5. ‘AS’ clause is used in SQL for
Ans: C
Ans:c
Ans: C
9. An entity set that does not have sufficient attributes to form a primary key is a
Ans: C
Page No 56
MCQ
Ans: A
Ans: A
Ans: C
Ans: A
Ans: B
Page No 57
(A) dependent on hardware.
Ans: D
Ans: B
Ans: A
Ans: D
Ans: A
Page No 58
MCQ
Ans: C
Ans: B
Ans: D
Ans: D
5. NULL is
Page No 59
Ans: D
Page No 60
MCQ
Consider the following tables SCHOOL and ADMIN. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
(i) To display TEACHERNAME, PERIODS of all teachers whose periods less than
25.
(ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL
and ADMIN whose gender is male.
(iii) To display number of teachers in each subject wise.
(iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who have
joined the school after 01/01/1999.
(v) SELECT MAX (EXPERIENCE), SUBJECT FROM SCHOOL GROUP BY
SUBJECT;
(vi) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE
DESIGNATION = ‘COORDINATOR’ AND SCHOOL.CODE=ADMIN.CODE;
(vii) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY
DESIGNATION HAVING COUNT (*) <2;
(viii) SELECT COUNT (DISTINCT SUBJECT) FROM SCHOOL;
Page No 61
MCQ
Page No 62
MCQ
CLASS TEST XX
Page No 63
MCQ
Page No 64
MCQ
2. What is Malware?
3. What is adware?
4. What is Spyware?
5. What is Phishing?
Page No 65
https://www.sanfoundry.com/python-quiz/
Page No 66
By InterviewMocks.com
Python MCQ Quiz
A. Yes
B. No
A. yes
B. no
C. machine dependent
D. none of the mentioned
A. 79 characters
B. 31 characters
C. 63 characters
D. none of the mentioned
A. foo
B. my_string_1
C. 1st_string
D. _
A. pass
B. assert
C. nonlocal
D. eval
A. UPPER CASE
B. Capitalized
C. lower case
D. None of the mentioned
A. __init__
B. in
C. it
D. on
A. //
B. /
C. %
D. None of the mentioned
A. 7
B. 1
C. 5
Q12. Which one of the following has the same precedence level?
A. Addition and Subtraction
B. Multiplication, Division and Addition
C. Multiplication, Division, Addition and Subtraction
D. Addition and Multiplication
Q13. Which one of the following has the highest precedence in the expression?
A. Exponential
B. Multiplication
C. Parentheses
D. Addition
A. Class
B. Lists
C. Tuples
D. Dictionary
Q15. Given a function that does not return any value, What value is thrown by default
when executed in shell.
A. int
B. None
C. bool
D. void
A. round(45.8)
B. round(6352.898,2,5)
C. round()
D. round(7463.123,2,1)
A. float
B. bool
C. int
D. dict
Q18. In order to store values in terms of key and value we use what core data type.
A. list
B. dictionary
C. class
D. tuple
A. ‘3\’
B. “He said, ‘Yes!'”
C. ‘”Once upon a time…”, she said.’
D. ”’That’s okay”’
A. True
B. False
C. Machine dependen
D. Error
A. k = 2 + 3j
B. k = complex(2, 3)
C. k = 2 + 3l
D. k = 2 + 3J
A. Complex
B. Float
C. Boolean
D. Integer
A. -3
B. -4
C. -5
D. +3
Q24. Which of the following is incorrect?
A. x = 0b101
B. x = 0x4f5
C. x = 19023
D. x = 03964
A. 7
B. 12
C. 0.75
D. 81
Q26. Which of the following operators has its associativity from right to left?
A. +
B. **
C. %
D. //
Q27. Which of the following expressions involves coercion when evaluated in Python?
A. 1.7 % 2
B. 4.7 – 1.5
C. 7.9 * 6.3
D. 3.4 + 4.6
A. float(‘10’)
B. int(’10.8’)
C. int(‘10’)
D. float(’10.8’)
A. ‘0b10111’
B. ‘0b11111’
C. ‘0b11011’
D. ‘0b11101’
Q30. Which of the following expressions results in an error?
A. int(‘1011’)
B. int(1011,2)
C. int(‘1011’,23)
D. int(1011)
Q31. Which of the following expressions can be used to multiply a given number ‘a’ by
4?
A. a<<4
B. a>>2
C. a<<2
D. a>>4
A. Error
B. No output
C. t
D. f
Q33. What will be the output of the following Python code snippet?
A. No output
B. Error
C. True
D. False
A. True
B. False
A. {‘san’, ‘foundry’}
B. san foundry
C. sanfoundry
D. Error
Q36. Select the valid option for the following Output ?
Q37. What will be the output of the following Python code if the input entered is 6?
A. NameError
B. AssignmentError
C. IOError
D. ValueError
A. a standard module
B. a special function
C. a module
D. an object
Q40. Which of the following blocks will be executed whether an exception is thrown or
not?
A. except
B. finally
C. else
D. assert
A. yes
B. no
A. UPPER CASE
B. lower case
C. Capitalized
D. None of the mentioned
Q4. Mathematical operations can be performed on a string. State whether true or false -
A. False
B. True
Q5. Which one of the following has the highest precedence in the expression?
A. Addition
B. Multiplication
C. Exponential
D. Parentheses
A. float
B. bool
C. dict
D. int
Q7. What is the output of the following? print("Hello {0!r} and {0!s}".format('foo', 'bin'))
A. String
B. Numbers
C. Slice
D. List
Q9. Which Of The Following Keywords Mark The Beginning Of The Class Definition?
A. return
B. class
C. def
D. All of the above
A. Yes
B. no
Q12. Python allows string slicing. What is the output of below code: s='cppbuzz chicago'
print(s[3:5])
A. buzzc
B. pbuzz
C. bu
D. None of these
Q13. class test: def __init__(self): print "Hello World" def __init__(self): print "Bye
World" obj=test()
A. Bye World
B. Hello World
C. Compilation Error
D. Ambiguity
A. list
B. bool
C. int
D. str
A. 32 characters
B. 63 characters
C. 79 characters
D. 31 Characters
Q17. Which one of the following is not a python's predefined data type?
A. List
B. Dictionary
C. Tuple
D. Class
A. 13
B. 15
C. 2
D. None of these
Q19. 19 % 2 in python
A. 2
B. 17
D. None of these
A. /
B. +
C. ()
D. -
Q21. Is Tuple mutable?
A. yes
B. no
Answer: a
Answer: d
Answer: d
Answer: b
Answer: a
Answer: a
Answer: d
Answer: a
Answer: b
Answer: b
Answer: b
Answer: b
Answer: a
Answer: b
Answer: b
Answer: a
Answer: c
Answer: a
The expression Int(x) implies that the variable x is converted to integer.
a) True
b) False
Answer: a
Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
Answer: d
Answer: d
Given a function that does not return any value, What value is thrown by default when
executed in shell.
a) int
b) bool
c) void
d) None
Answer: d
advertisement
1.>>>str="hello"
2.>>>str[:2]
3.>>>
a) he
b) lo
c) olleh
d) hello
Answer: a
Answer: a
Answer: a
1.>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned
Answer: d
What error occurs when you execute the following Python code snippet?
apple = mango
a)SyntaxError
b)NameError
c)ValueError
d) TypeError
Answer: b
1.def example(a):
2. a = a + '2'
3. a = a*2
4. return a
5.>>>example("hello")
indentation Error
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2
Answer: a
a)list
b)dictionary
c)array
d) tuple
Answer: a
In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary
Answer: d
Answer: c
The following is displayed by a print function call. Select all of the function calls that
result in this output.
1.tom
2.dick
3.harr
a)
print('''tom
\ndick
\nharry''')
b) print(”’tomdickharry”’)
c) print(‘tom\ndick\nharry’)
d)
print('tom
dick
harry')
Answer: c
1.>>>grade1 = 80
2.>>>grade2 = 90
3.>>>average = (grade1 + grade2) / 2
a) 85.0
b) 85.1
c) 95.0
d) 95.1
Answer: a
hello-how-are-you
Answer: c
What is the return value of trunc()?
a) int
b) bool
c) float
d) None
Answer: a
. Which is the correct operator for power(xy)?
a) X^y
b) X**y
c) X^^y
d) None of the mentioned
Answer: b
Which one of these is floor division?
a) /
b) //
c) %
d) None of the mentioned
Answer: b
What is the order of precedence in python?
i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction
a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v
Answer: a
What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
Answer: b
. Mathematical operations can be performed on a string.
a) True
b) False
Answer: b
Operators with the same precedence are evaluated in which manner?
a) Left to Right
b) Right to Left
c) Can’t say
d) None of the mentioned
Answer: a
What is the output of this expression, 3*1**3?
a) 27
b) 9
c) 3
d) 1
Answer: c
Which one of the following has the same precedence level?
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
Answer: a
he expression Int(x) implies that the variable x is converted to integer.
a) True
b) False
Answer: a
Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
Answer: d
What is the output of print 0.1 + 0.2 == 0.3?
a) True
b) False
c) Machine dependent
d) Error
Answer: b
Which of the following is not a complex number?
a) k = 2 + 3j
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J
Answer: c
4 + 3 % 5
a) 4
b) 7
c) 2
d) 0
Answer: b
Evaluate the expression given below if A = 16 and B = 15
A % B // A
a 0.0
b) 0
c) 1.0
d) 1
Answer: b
Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **
Answer: d
What will be the value of x in the following Python expression?
x = int(43.55+2/2)
a)43
b) 44
c) 22
d) 23
Answer: a
Which of the following is the truncation division operator?
a) /
b) %
c) //
d) |
Answer: c
What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a)64, 512, 64
b) 64, 64, 64
c) 512, 512, 512
d) 512, 64, 512
Answer: d
8/4/2, 8/(4/2)
a)(1.0, 4.0)
b) (1.0, 1.0)
c) (4.0. 1.0)
d) (4.0, 4.0)
Answer: a
float(22//3+3/3)
a) 8
b) 8.0
c) 8.3
d) 8.33
Answer: b
print(4.00/(2.0+2.0))
a)Error
b)1.0
c)1.00
d) 1
Answer: b
X = 2+9*((3*12)-8)/10
a) 30.0
b) 30.8
c) 28.4
d) 27.2
Answer: d
Answer: c
24//6%3, 24//4//2
a) (1,3)
b) (0,3)
c) (1,0)
d) (3,1)
Answer: a
Which among the following list of operators has the highest precedence?
float(4+int(2.39)%2)
a) 5.0
b) 5
c) 4.0
d) 4
Answer: c
Which of the following expressions is an example of type conversion?
a) 4.0 + float(3)
b) 5.3 + 6.3
c) 5.0 + 3
d) 3 + 7
Answer: a
Which of the following expressions results in an error?
a) float(‘10’)
b) int(‘10’)
c) float(’10.8’)
d) int(’10.8’)
Answer: d
What will be the value of the following Python expression?
4+2**5//10
a) 3
b) 7
c) 77
d) 0
Answer: b
10. The expression 2**2**3 is evaluates as: (2**2)**3.
a) True
b) False
Answer: b
1. What will be the output of the following Python code snippet if x=1?
x<<2
a) 8
b) 1
c) 2
d) 4
Answer: d
What will be the output of the following Python expression?
bin(29)
a) ‘0b10111’
b) ‘0b11101’
c) ‘0b11111’
d) ‘0b11011’
Answer: b
What will be the value of x in the following Python expression, if the result of that
expression is 2?
x>>2
a) 8
b) 4
c) 2
d) 1
nswer: a
int(1011)?
a) 1011
b) 11
c) 13
d) 1101
Answer: a
To find the decimal value of 1111, that is 15, we can use the function:
a) int(1111,10)
b) int(‘1111’,10)
c) int(1111,2)
d) int(‘1111’,2)
Answer: d
What will be the output of the following Python expression if x=15 and y=12?
x & y
a) b1101
b) 0b1101
c) 12
d) 1101
Answer: c
Which of the following expressions results in an error?
a) int(1011)
b) int(‘1011’,23)
c) int(1011,2)
d) int(‘1011’)
Answer: c
Which of the following represents the bitwise XOR operator?
a) &
b) ^
c) |
d) !
Answer: b
What is the value of the following Python expression?
bin(0x8)
a) ‘0bx1000’
b) 8
c) 1000
d) ‘0b1000’
Answer: d
What will be the output of the following Python expression?
0x35 | 0x75
a) 115
b) 116
c) 117
d) 118
Answer: c
It is not possible for the two’s complement value to be equal to the original value in any
case.
a) True
b) False
Answer: b
The one’s complement of 110010101 is:
a) 001101010
b) 110010101
c) 001101011
d) 110010100
Answer: a
Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
a) OR
b) AND
c) XOR
d) NOT
Answer: c
What will be the output of the following Python expression?
4^12
a) 2
b) 4
c) 8
d) 12
Answer: c
Any odd number on being AND-ed with ________ always gives 1. Hint: Any even
number on being AND-ed with this value always gives 0.
a) 10
b) 2
c) 1
d) 0
Answer: c
What will be the value of the following Python expression?
bin(10-2)+bin(12^4)
a) 0b10000
b) 0b10001000
c) 0b1000b1000
d) 0b10000b1000
Answer: d
Which of the following expressions can be used to multiply a given number ‘a’ by 4?
a) a<<2
b) a<<4
c) a>>2
d) a>>4
Answer: a
What will be the output of the following Python code if a=10 and b =20?
a=10
b=20
a=a^b
b=a^b
a=a^b
print(a,b)
a) 10 20
b) 10 10
c) 20 10
d) 20 20
Answer: c
What is the two’s complement of -44?
a) 1011011
b) 11010100
c) 11101011
d) 10110011
Answer: b
~100?
a) 101
b) -101
c) 100
d) -100
Answer: b
What will be the output of the following Python code snippet?
bool(‘False’)
bool()
a)
True
True
b)
False
True
c)
False
False
d)
True
False
Answer: d
['hello', 'morning'][bool('')]
a) error
b) no output
c) hello
d) mornin
Answer: c
What will be the output of the following Python code snippet?
not(3>4)
not(1&1)
a)
True
True
b)
True
False
c)
False
True
d)
False
False
Answer: b
What will be the output of the following Python code?
['f', 't'][bool('spam')]
a) t
b) f
c) No output
d) Error
Answer: a
What will be the output of the following Python code?
a) Error
b) [1, 0, 2, 0, ‘hello’, ”, []]
c) [1, 0, 2, ‘hello’, ”, []]
d) [1, 2, ‘hello’]
Answer: d
What will be the output of the following Python code if the system date is 21st June,
2017 (Wednesday)?
[] or {}
{} or []
a)
[]
{}
b)
[]
[]
c)
{}
[]
d)
{}
{}
Answer: c
What will be the output of the following Python code?
class Truth:
pass
x=Truth()
bool(x)
a) pass
b) true
c) false
d) error
Answer: b
What will be the output of the following Python code?
a) error
b) hello
c) good
d) bad
Answer: c
Which of the following Boolean expressions is not logically equivalent to the other
three?
a) not(-6<0 or-6>10)
b) -6>=0 and -6<=10
c) not(-6<10 or-6==10)
d) not(-6>10 or-6==10)
Answer: d
What will be the output of the following Python code snippet?
a) True
b) False
c) Error
d) No output
X=”hi”
print(“05d”%X)
a) 00000hi
b) 000hi
c) hi000
d) error
Answer: d
What will be the output of the following Python code snippet?
X=”san-foundry”
print(“%56s”,X)
a) 56 blank spaces before san-foundry
b) 56 blank spaces before san and foundry
c) 56 blank spaces after san-foundry
d) no change
Answer: a
What will be the output of the following Python expression if x=456?
print("%-06d"%x)
a) 000456
b) 456000
c) 456
d) error
Answer: c
What will be the output of the following Python expression if X=345?
print(“%06d”%X)
a) 345000
b) 000345
c) 000000345
d) 345000000
Answer: b
Which of the following formatting options can be used in order to add ‘n’ blank spaces
after a given string ‘S’?
a) print(“-ns”%S)
b) print(“-ns”%S)
c) print(“%ns”%S)
d) print(“%-ns”%S)
Answer: d
What will be the output of the following Python expression if X = -122?
print("-%06d"%x)
a) -000122
b) 000122
c) –00122
d) -00122
Answer: c
What will be the output of the following Python expression if the value of x is 34?
print(“%f”%x)
a) 34.00
b) 34.0000
c) 34.000000
d) 34.00000000
Answer: c
What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
a) 56.00
b) 56.24
c) 56.23
d) 0056.236
Answer: b
What will be the output of the following Python expression if x=22.19?
print("%5.2f"%x)
a) 22.1900
b) 22.00000
c) 22.19
d) 22.20
Answer: c
The expression shown below results in an error.
print("-%5d0",989)
a) True
b) False
Answer: b
What will be the output of the following Python code snippet?
'%d %s %g you' %(1, 'hello', 4.0)
a) Error
b) 1 hello you 4.0
c) 1 hello 4 you
d) 1 4 hello you
Answer: c
The output of which of the codes shown below will be: “There are 4 blue birds.”?
a) ‘There are %g %d birds.’ %4 %blue
b) ‘There are %d %s birds.’ %(4, blue)
c) ‘There are %s %d birds.’ %[4, blue]
d) ‘There are %d %s birds.’ 4, blue
Answer: b
What will be the output of the python code shown below for various styles of format
specifiers?
x=1234
res='integers:...%d...%-6d...%06d' %(x, x, x)
res
a) ‘integers:…1234…1234 …001234’
b) ‘integers…1234…1234…123400’
c) ‘integers:… 1234…1234…001234’
d) ‘integers:…1234…1234…001234’
Answer: a
What will be the output of the following Python code snippet?
x=3.3456789
'%f | %e | %g' %(x, x, x)
a) Error
b) ‘3.3456789 | 3.3456789+00 | 3.345678’
c) ‘3.345678 | 3.345678e+0 | 3.345678’
d) ‘3.345679 | 3.345679e+00 | 3.3456
Answer: d
Answer: a
What will be the output of the following Python code snippet?
x=3.3456789
'%s' %x, str(x)
a) Error
b) (‘3.3456789’, ‘3.3456789’)
c) (3.3456789, 3.3456789)
d) (‘3.3456789’, 3.3456789)
Answer: b
Answer: d
What will be the output of the following Python code snippet?
a='hello'
q=10
vars()
a) {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
b) {……Built in names set by Python……}
c) {‘a’ : ‘hello’, ‘q’ : 10}
d) Error
Answer: a
What will be the output of the following Python code?
Answer: d
What will be the output of the following Python code?
Answer: a
What will be the output of the following Python code?
Answer: b
What will be the output of the following Python code?
'{0:.2f}'.format(1.234)
a) ‘1’
b) ‘1.234’
c) ‘1.23’
d) ‘1.2’
Answer: c
i. '{0:.2f}'.format(1/3.0)
ii. '%.2f'%(1/3.0)
a) True
b) False
Answer: a
What will be the output of the following Python code?
l=list('HELLO')
'first={0[0]}, third={0[2]}'.format(l)
a) ‘first=H, third=L’
b) ‘first=0, third=2’
c) Error
d) ‘first=0, third=L’
Answer: a
l=list('HELLO')
p=l[0], l[-1], l[1:3]
'a={0}, b={1}, c={2}'.format(*p)
a) Error
b) “a=’H’, b=’O’, c=(E, L)”
c) “a=H, b=O, c=[‘E’, ‘L’]”
d) Junk value
Answer: c
The formatting method {1:<10} represents the ___________ positional argument,
_________ justified in a 10 character wide field.
a) first, right
b) second, left
c) first, left
d) second, right
Answer: b
What will be the output of the following Python code?
Answer: d
Answer: a
'{a}{b}{a}'.format(a='hello', b='world')
a) ‘hello world’
b) ‘hello’ ‘world’ ‘hello’
c) ‘helloworldhello’
d) ‘hello’ ‘hello’ ‘world’
Answer: c
D=dict(p='san', q='foundry')
'{p}{q}'.format(**D)
a) Error
b) sanfoundry
c) san foundry
d) {‘san’, ‘foundry’}
Answer: b
What will be the output of the following Python code?
Answer: a
What will be the output of the following Python code?
Answer: d
Answer: b
What will be the output of the following Python code?
'%s' %((1.23,),)
a) ‘(1.23,)’
b) 1.23,
c) (,1.23)
d) ‘1.23’
Answer: a
What will be the output of the following two codes?
i. '{0}'.format(4.56)
ii. '{0}'.format([4.56,])
a) ‘4.56’, ‘4.56,’
b) ‘4.56’, ‘[4.56]’
c) 4.56, [4.56,]
d) 4.56, [4.56,]
Answer: b
What will be the output of the following Python code?
def mk(x):
def mk1():
print("Decorated")
x()
return mk1
def mk2():
print("Ordinary")
p = mk(mk2)
p()
a)
Decorated
Decorated
b)
Ordinary
Ordinary
c)
Ordinary
Decorated
d)
Decorated
Ordinary
Answer: d
In the following Python code, which function is the decorator?
def mk(x):
def mk1():
print("Decorated")
x()
return mk1
def mk2():
print("Ordinary")
p = mk(mk2)
p()
a) p()
b) mk()
c) mk1()
d) mk2()
Answer: b
The ______ symbol along with the name of the decorator function can be placed above
the definition of the function to be decorated works as an alternate way for decorating a
function.
a) #
b) $
c) @
d) &
Answer: c
what will be the output of the following Python code?
def ordi():
print("Ordinary")
ordi
ordi()
a)
Address
Ordinary
b)
Error
Address
c)
Ordinary
Ordinary
d)
Ordinary
Address
Answer: a
The two snippets of the following Python codes are equivalent.
CODE 1
@f
def f1():
print(“Hello”)
CODE 2
def f1():
print(“Hello”)
f1 = f(f1)
a) True
b) False
Answer: a
b)
Zero Division Error
c)
d)
Answer: c
What will be the output of the following Python code?
def f(x):
def f1(a, b):
print("hello")
if b==0:
print("NO")
return
return f(a, b)
return f1
@f
def f(a, b):
return a%b
f(4,0)
a)
hello
NO
b)
hello
c) NO
d) hello
Answer: a
What will be the output of the following Python code?
def f(x):
def f1(*args, **kwargs):
print("*"* 5)
x(*args, **kwargs)
print("*"* 5)
return f1
def a(x):
def f1(*args, **kwargs):
print("%"* 5)
x(*args, **kwargs)
print("%"* 5)
return f1
@f
@a
def p(m):
print(m)
p("hello")
a)
*****
%%%%%
hello
%%%%%
*****
b) Error
c) *****%%%%%hello%%%%%*****
d) hello
Answer: a
The following python code can work with ____ parameters.
def f(x):
def f1(*args, **kwargs):
print("Sanfoundry")
return x(*args, **kwargs)
return f1
a) 2
b) 1
c) any number of
d) 0
Answer: c
What will be the output of the following Python code?
def f(x):
def f1(*args, **kwargs):
print("*", 5)
x(*args, **kwargs)
print("*", 5)
return f1
@f
def p(m):
p(m)
print("hello")
a)
*****
hello
b)
*****
*****
hello
c) *****
d) hello
Answer: d
A function with parameters cannot be decorated.
a) True
b) False
Answer: b
Identify the decorator in the snippet of code shown below.
def sf():
pass
sf = mk(sf)
@f
def sf():
return
a) @f
b) f
c) sf()
d) mk
Answer: d
What will be the output of the following Python code?
class A:
@staticmethod
def a(x):
print(x)
A.a(100)
a) Error
b) Warning
c) 100
d) No output
Answer: c
What will be the output of the following Python code?
def d(f):
def n(*args):
return '$' + str(f(*args))
return n
@d
def p(a, t):
return a + a*t
print(p(100,0))
a) 100
b) $100
c) $0
d) 0
Answer: b
What will be the output of the following Python code?
def c(f):
def inner(*args, **kargs):
inner.co += 1
return f(*args, **kargs)
inner.co = 0
return inner
@c
def fnc():
pass
if __name__ == '__main__':
fnc()
fnc()
fnc()
print(fnc.co)
a) 4
b) 3
c) 0
d) 1
Answer: b
What will be the output of the following Python code?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
a) [‘ab’, ‘cd’]
b) [‘AB’, ‘CD’]
c) [None, None]
d) none of the mentioned
Answer: a
x = ['ab', 'cd']
for i in x:
x.append(i.upper())
print(x)
a) [‘AB’, ‘CD’]
b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
c) [‘ab’, ‘cd’]
d) none of the mentioned
Answer: d
What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i)
i + = 1
a) 1 2
b) 1 2 3
c) error
d) none of the mentioned
Answer: c
i = 1
while True:
if i%0O7 == 0:
break
print(i)
i += 1
a) 1 2 3 4 5 6
b) 1 2 3 4 5 6 7
c) error
d) none of the mentioned
Answer: a
What will be the output of the following Python code?
i = 5
while True:
if i%0O11 == 0:
break
print(i)
i += 1
a) 5 6 7 8 9 10
b) 5 6 7 8
c) 5 6
d) error
Answer: b
What will be the output of the following Python code?
i = 5
while True:
if i%0O9 == 0:
break
print(i)
i += 1
a) 5 6 7 8
b) 5 6 7 8 9
c) 5 6 7 8 9 10 11 12 13 14 15 ….
d) error
Answer: d
What will be the output of the following Python code?
i = 1
while True:
if i%2 == 0:
break
print(i)
i += 2
a) 1
b) 1 2
c) 1 2 3 4 5 6 …
d) 1 3 5 7 9 11 …
Answer: d
What will be the output of the following Python code?
i = 2
while True:
if i%3 == 0:
break
print(i)
i += 2
a) 2 4 6 8 10 …
b) 2 4
c) 2 3
d) error
Answer: b
What will be the output of the following Python code?
i = 1
while False:
if i%2 == 0:
break
print(i)
i += 2
a) 1
b) 1 3 5 7 …
c) 1 2 3 4 …
d) none of the mentioned
Answer: d
What will be the output of the following Python code?
True = False
while True:
print(True)
break
a) True
b) False
c) None
d) none of the mentioned
Answer: d
What will be the output of the following Python code?
i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) 0 1 2 0
b) 0 1 2
c) error
d) none of the mentioned
Answer: b
What will be the output of the following Python code?
i = 0
while i < 3:
print(i)
i += 1
else:
print(0)
a) 0 1 2 3 0
b) 0 1 2 0
c) 0 1 2
d) error
Answer: b
What will be the output of the following Python code?
x = "abcdef"
while i in x:
print(i, end=" ")
a) a b c d e f
b) abcdef
c) i i i i i i …
d) error
Answer: d
x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")
a) no output
b) i i i i i i …
c) a b c d e f
d) abcdef
Answer: a
What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
a) no output
b) i i i i i i …
c) a a a a a a …
d) a b c d e f
x = "abcdef"
i = "a"
while i in x:
print('i', end = " ")
a) no output
b) i i i i i i …
c) a a a a a a …
d) a b c d e f
Answer: b
What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")
a) i i i i i i
b) a a a a a a
c) a a a a a
d) none of the mentioned
Answer: b
What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x[:-1]:
print(i, end = " ")
a) a a a a a
b) a a a a a a
c) a a a a a a …
d) a
Answer: c
What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
x = x[1:]
print(i, end = " ")
a) a a a a a a
b) a
c) no output
d) error
Answer: b
What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x[1:]:
print(i, end = " ")
a) a a a a a a
b) a
c) no output
d) error
Answer: c
What will be the output of the following Python code?
x = 'abcd'
for i in x:
print(i)
x.upper()
a) a B C D
b) a b c d
c) A B C D
d) error
Answer: b
What will be the output of the following Python code?
x = 'abcd'
for i in x:
print(i.upper())
a) a b c d
b) A B C D
c) a B C D
d) error
Answer: b
What will be the output of the following Python code?
x = 'abcd'
for i in range(x):
print(i)
a) a b c d
b) 0 1 2 3
c) error
d) none of the mentioned
Answer: c
What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
print(i)
a) a b c d
b) 0 1 2 3
c) error
d) 1 2 3 4
Answer: b
x = 'abcd'
for i in range(len(x)):
print(i.upper())
a) a b c d
b) 0 1 2 3
c) error
d) 1 2 3 4
Answer: c
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
Answer: c
What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
x[i].upper()
print (x)
a) abcd
b) ABCD
c) error
d) none of the mentioned
Answer: a
x = 'abcd'
for i in range(len(x)):
i[x].upper()
print (x)
a) abcd
b) ABCD
c) error
d) none of the mentioned
Answer: c
What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)
a) a
b) abcd abcd abcd
c) a a a a
d) none of the mentioned
Answer: c
What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
print(x)
x = 'a'
a) a
b) abcd abcd abcd abcd
c) a a a a
d) none of the mentioned
Answer: d
What will be the output of the following Python code?
x = 123
for i in x:
print(i)
a) 1 2 3
b) 123
c) error
d) none of the mentioned
Answer: c
Answer: a
What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in d:
print(x, y)
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned
Answer: d
What will be the output of the following Python code?
Answer: c
What will be the output of the following Python code?
Answer: b
What will be the output of the following Python code?
Answer: b
What will be the output of the following Python code?
Answer: d
What will be the output of the following Python code?
d = {0, 1, 2}
for x in d.values():
print(x)
a) 0 1 2
b) None None None
c) error
d) none of the mentioned
Answer: c
What will be the output of the following Python code?
d = {0, 1, 2}
for x in d:
print(x)
a) 0 1 2
b) {0, 1, 2} {0, 1, 2} {0, 1, 2}
c) error
d) none of the mentioned
Answer: a