0% found this document useful (0 votes)
2K views307 pages

5 - 6255737462828565350 (10 Files Merged)

The document provides a summary of key concepts in digital electronics including: 1. Converting between number systems such as decimal to binary and hexadecimal to decimal. 2. Understanding logic gates and boolean expressions. Questions cover topics like minimization of boolean functions using K-maps. 3. Common digital components like multiplexers, decoders, adders. Questions test understanding of these components including their inputs, outputs and applications. 4. Error detection and correction codes such as hamming codes. The questions range from easy to moderate difficulty and cover a wide breadth of foundational digital electronics topics in two summarized units.

Uploaded by

Aman Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views307 pages

5 - 6255737462828565350 (10 Files Merged)

The document provides a summary of key concepts in digital electronics including: 1. Converting between number systems such as decimal to binary and hexadecimal to decimal. 2. Understanding logic gates and boolean expressions. Questions cover topics like minimization of boolean functions using K-maps. 3. Common digital components like multiplexers, decoders, adders. Questions test understanding of these components including their inputs, outputs and applications. 4. Error detection and correction codes such as hamming codes. The questions range from easy to moderate difficulty and cover a wide breadth of foundational digital electronics topics in two summarized units.

Uploaded by

Aman Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 307

Digital Electronics KEE-401

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

2. The following hexadecimal number (1E.43)16 is equivalent to

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

4. The representation of octal number (532.2)8 in decimal is ________

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) 6 * 162 + 13 * 161 + 14 * 160


b) 6 * 162 + 12 * 161 + 13 * 160
c) 6 * 162 + 11 * 161 + 14 * 160
d) 6 * 162 + 14 * 161 + 15 * 160
e)None of the above
Answer :a

6. 1’s complement can be easily obtained by using _________

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

8. The BCD code for a decimal(874)10 is

a) 100001110100
b) 010001111000
c) 100001000111
d) 011110000100
e) None of the above

Answer :a

9. The Boolean function A+BC is a reduced form of

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

11. The expression Y=(A+B)(B+C)(C+A) shows the _________ operation.

a) AND
b) POS
c) SOP
d) NAND
e)None of the above

Answer:b

12. Convert the hexadecimal number (1E2)16 to decimal.

a) 480
b) 483
c) 482
d) 484
e)None

Answer:c

13. What is addition of (-64)10 and (80)16?

a) (-16)10
b) (16)10
c) (11000000)2
d) (01000000)2
e) None of the above

Answer:d

14. (28)8 is expressed in gray code as which of the following


a) 11000
b) 10100
c) 11110
d) 11111
e) 10101

Answer:c

15. If (135)x +(144)x=(323)x then the value of X

a) 5
b) 3
c) 12
d) 6
e) None of the above

Answer:d

16. What is the gray code for binary 101011

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

19. Which of the following is complement of essential prime implicant


F(w,x,y,z)= wy+ xy + w’xyz + w’x’y + xz + x’y’z’

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

20. The minterms expansion of f(P,Q,R)=PQ+QR’+PR’ is

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

21. On subtracting +28 and +29 using 2’s complement,we get

a) 111111001
b) 000000101
c) 111111010
d) 010101011
e) None of the above

Answer:b

22. Excess -3 code for 597 is given by

a) 100011001010
b) 010110010111
c) 010110101101
d) 100010100111
e) None of the above

Answer:b
23. Product of sum expression can be implemented using:

a) Both 2 –level OR-AND and NOR logic circuits


b) 2-level XOR logic circuits
c) 2-level OR –AND logic circuits
d) 2-level NOR logic circuits
e) None of the above

Answer : a

24. Which of the following is/are non-weighted code.


A. 8-4-2-1 code
B. BCD
C. Excess-3
D. Gray code

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

a) F=AD’+AC+B’C and No. of two input NAND gate required=4


b) F=AD’+AC+B’C and No. of two input NAND gate required=6
c) F=A’D’+AC+AB’C and No. of two input NAND gate required=4
d) F=A’D’+AC+AB’C and No. of two input NAND gate required=6
e) None of the above

Answer: b

26. Minimize following 3 variable functions.


f(A,B,C,)= ∑m(0,1,6,7)

a) A’B’+AB
b) A+B
c) AB+C’
d) A’+BC’
e) None of the above
Answer: a

27. Minimize f = ∑m(1,5,6,12,13,14) + d(4) in SOP minimal form:

a) f = BC' + BC’D' + A'C'D


b) f = BC' + BD' + A'C'D
c) f= BC' D+ ABD' + A'C'D
d) f= BC' + BCD' + A'C'D
e) None of the above

Answer: b

28. Simplify the following:


F= ((A+BC')'+D(E+F')')'

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

29. Convert (100001011001)BCD to Excess-3 code

a) (1011 1010 1100)Excess-3


b) (1111 1001 1100) Excess-3
c) (1011 1000 1100) Excess-3
d) (1000 1000 1100) Excess-3
e) None of the above

Answer :c

30. Why do we require hamming codes?


a) Error correction
b) Encryption only
c) Decryption
d) Bit stuffing
e)none of the above

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

2. The device shown here is most likely a ________

a) Comparator
b) Multiplexer
c) Adder
d) Demultiplexer
e)none of the above

Answer:d

3. In a multiplexer the output depends on its ____________


a) Data inputs
b) Select inputs
c) Select outputs
d) Enable pin
e)none of the above

Answer: b

4. __________can be used as parallel to series converter.


a) Decoder
b) Multiplexer
c) Adder
d) Demultiplexer
e) None of the above

Answer :b

5. The number of 4x16 decoder required to implement 8 x 256 decoder


a) 16
b) 17
c) 32
d) 48
e) None of the above

Answer :e

6. A digital multiplexer can be used for


1) Parallel to serial conversion
2) Many to one switch
3) Generating memory chip select
4) Code conversion
a) 1,2 and 3
b) Only 1
c) 1 and 2 only
d) 1 and 3 only
e) 2 and 3 only

Answer :d

7. How many inputs are required for a 1-of-10 BCD decoder?


a) 4
b) 8
c) 10
d) 2
e)none of the above

Answer :a

8. Which of the following statements is not correct


a) A full adder can be constructed using two half adder and an OR gate
b) Two four bit parallel adder can be cascaded to construct 8-bit parallel adder.
c) Ripple carry adder has addition time independent to the number of bits
d) Carry look ahead adder is used to speed up the parallel addition.
e) None of the above

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

10. What distinguishes the look-ahead-carry adder?


a) It is slower than the ripple-carry adder
b) It is easier to implement logically than a full adder
c) It is faster than a ripple-carry adder
d) It requires advance knowledge of the final answer
e)None of the above

Answer: c

11. What is one disadvantage of the ripple-carry adder?


a) The interconnections are more complex
b) More stages are required to a full adder
c) It is slow due to propagation time
d) All of the Mentioned
e)None of the aove

Answer: c

12. In 1-to-4 multiplexer, if C1 = 1 & C2 = 1, then the output will be ____________


a) Y0
b) Y1
c) Y2
d) Y3
e)Invalid output

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

20. A binary full-subtractor


a) Consists of two cascaded half- subtractor
b) Contains two half -subtractor and one OR gate.
c) Can subtract any binary number
d) Can be implement out of full adder
e) None of the above

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

25. Procedure for the design of combinational circuits are:

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

C. Simplify the switching expression(s) for the output(s).


D. Implement the simplified expression using logic gates.

E. Write down the switching expression(s) for the output(s).

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

26. A digital system consists of _____ types of circuits.


a) 2
b) 3
c) 4
d) 5
e)none of the above

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

30. Half-adders have a major limitation in that they cannot __________


a) Accept a carry bit from a present stage
b) Accept a carry bit from a next stage
c) Accept a carry bit from a previous stage
d) Accept a carry bit from the following stages
e)No limitations

Answer: c
UNIT 3

1. How would you describe the counter shown in the figure?

a) 3-bit binary synchronous up counter


b) 3-bit binary ripple up counter
c) 3-bit binary synchronous down counter
d) 3-bit binary ripple down counter
e) None of the above

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

3. When both inputs of SR latches are low, the latch ___________


a) Q output goes high
b) Q’ output goes high
c) It remains in its previously set or reset state
d) it goes to its next set or reset state
e)none of the above

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

8. 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 the these

Answer: c

9. A register is defined as ___________


a) The group of latches for storing one bit of information
b) The group of latches for storing n-bit of information
c) The group of flip-flops suitable for storing one bit of information
d) The group of flip-flops suitable for storing binary information
e)none of these

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

12. Master Slave Flip flop consist of :


a)2 Flip flop
b)3 Flip flop
c)4 Flip flop
d)5 Flip flop
e)none of the above

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

16. High speed counter is ____________


a) Ring counter
b) Ripple counter
c) Synchronous counter
d) Asynchronous counter

Answer: c

17. Which of the following statements are true?


a) Asynchronous events does not occur at the same time
b) Asynchronous events are controlled by a clock
c) Synchronous events does not need a clock to control them
d) Only asynchronous events need a control clock
e)none of the above

Answer :a

18. In a 3-bit asynchronous down counter, the initial content is ____________


a) 000
b) 111
c) 010
d) 101
e)100
Answer :a

19. Consider the following statements:


1) Race around condition occurs in a JK flip flop when both the inputs are one.
2) A flip flop is used to store one bit of information.
3) A transparent latch consists of D flip flop
4) Master –slave configuration in flip flop to store two bit of information
Which of these statements are correct:
a) 1,2,and 3
b) 1,3 and 4
c) 1,2 and 4
d) 2,3 and 4
e) None of these

Answer :a

20. Assertion (A):An unclocked flip flop is called latch.


Reason( R):A latch is constructed using two cross coupled NAND gates or NOR gates
a) Both A and R are true,and R is the correct explaination of A
b) Both A and R are true,and R is not the correct explaination of A
c) A is true but R is false
d) A is false but R is true
e) None of these

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

27. Assertion (A):A flip flop is bistable multi vibrator


Reason( R):A flip flop remains in one stable state indefinitely until it is directed by an
input signal to switch over the other stable state
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 :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

30. In a parallel in/parallel out shift register, D0 = 1, D1 = 1, D2 = 1, and D3 = 0. After three


clock pulses, the data outputs are ________
a) 1110
b) 0001
c) 1100
d) 1000
e) none of the above
Answer: a
UNIT 4
1. How many natural states will there be in a 4-bit ripple counter?
a) 4
b) 8
c) 16
d) 32
e)None of the above.

Answer: c

2. One of the major drawbacks to the use of asynchronous counters is that


a) Low-frequency applications are limited because of internal propagation delays
b) High-frequency applications are limited because of internal propagation delays
c) Asynchronous counters do not have major drawbacks and are suitable for use in high-
and low-frequency counting applications
d) Asynchronous counters do not have propagation delays, which limits their use in high-
frequency applications
e)none of the above

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

4. Which of the following statement is correct ?


a) Mealy machine output depends on input only.
b) Mealy machine output depends on input and current state.
c) Moore machine output depends on input only.
d) Moore machine output depends on input and current state
e) None of the above

Answer: b

5. Two states are said to be equivalent if:


a) Set of inputs generate exactly same output
b) Set of inputs generate exactly same output and same next state
c) Set of inputs generate exactly same next state
d) All of the above
e) None of the above

Answer: b

6. The process of assigning states of a physical device to sates of a sequential machine is


known as
a) State reduction
b) State assignment
c) State table
d) States
e) None of the above

Answer: c

7. The number of directed arcs terminating on any of state diagram is:


a) 2n, where n is no. of input
b) 2n, where n is no. of flip flop in circuit
c) Independent of no. of input
d) Independent of no. of output
e) None of the above

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

9. A ripple counter’s speed is limited by the propagation delay of ____________


a) Each flip-flop
b) All flip-flops and gates
c) The flip-flops only with gates
d) Only circuit gates
e)none of the above

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

11. A ripple counter’s speed is limited by the propagation delay of __________


a) Each flip-flop
b) All flip-flops and gates
c) The flip-flops only with gates
d) Only circuit gates
e)none of the above

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

14. Modulus refers to ____________


a) A method used to fabricate decade counter units
b) The modulus of elasticity, or the ability of a circuit to be stretched from one mode to
another
c) An input on a counter that is used to set the counter state, such as UP/DOWN
d) The maximum number of states in a counter sequence
e) none of the above.

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

16. Program counter in a digital computer ____________


a) Counts the number of programs run in the machine
b) Counts the number of times a subroutine
c) Counts the number of time the loops are executed
d) Points the memory address of the current or the next instruction
e) none of the above

Answer: d

17. High speed counter is ____________


a) Ring counter
b) Ripple counter
c) Synchronous counter
d) Asynchronous counter
e) none of the above

Answer: c

18. A down counter using n-flip-flops count ______________


a) Downward from a maximum count
b) Upward from a minimum count
c) Downward from a minimum to maximum count
d) Toggles between Up and Down count
e) none of the above

Answer: a

19. In order to check the CLR function of a counter ____________


a) Apply the active level to the CLR input and check all of the Q outputs to see if they are
all in their reset state
b) Ground the CLR input and check to be sure that all of the Q outputs are LOW
c) Connect the CLR input to Vcc and check to see if all of the Q outputs are HIGH
d) Connect the CLR to its correct active level while clocking the counter; check to make
sure that all of the Q outputs are toggling
e) none of the above

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

23. Which type of triggering phenomenon is exhibited by Counters?


a) Edge
b) Level
c) Pulse
d) All of the above
e) none of the above

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?

a) Previous state decoder


b) Present state decoder
c) Next state decoder
d) Output state decoder
e) none of the above

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

2. Which type of device FPGA are?


a) SLD
b) SROM
c) EPROM
d) PLD
e) none of the above

Answer – d

3. PLA can be use:


a) As a microprocessor
b) As a Dynamic memory
c) To realize a sequential logic circuit.
d) To realize a combinational logic circuit
e) none of the above

Answer: d

4. A PLA is similar to a ROM in concept except that:


a) It hasn’t capability to read only
b) It hasn’t capability to read or write operation
c) It doesn’t provide full decoding to the variables
d) It hasn’t capability to write only
e) none of the above

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

8. Density of Dynamic RAM is


a) More than that of static RAM
b) Less than that of the static RAM
c) Equal to that of static RAM
d) Equal to or more than that of the static RAM
e) none of the above

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

12. The full form of PLD is _________


a) Programmable Load Devices
b) Programmable Logic Data
c) Programmable Logic Devices
d) Programmable Loaded Devices
e) none of the above

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

14. Why antifuses are implemented in a PLD?


a) To protect from high voltage
b) To increase the memory
c) To implement the programmes
d) As a switching devices
e) none of the above

Answer: c

15. Which logic is the fastest of all the logic families?


a) TTL
b) ECL
c) HTL
d) DTL.
e) none of the above

Answer: b

16. Sometimes ECL can also be named as __________


a) EEL
b) CEL
c) CML
d) CCL
e) none of the above

Answer: c

17. In an ECL the output is taken from __________


a) Emitter
b) Base
c) Collector
d) Junction of emitter and base
e) none of the above

Answer: c

18. The ECL behaves as __________


a) NOT gate
b) NOR gate
c) NAND gate
d) AND gate
e) none of the above

Answer: b

19. In ECL the fanout capability is __________


a) High
b) Low
c) Zero
d) Sometimes high and sometimes low
e) none of the above

Answer: a

20. ECL’s major disadvantage is that __________


a) It requires more power
b) It’s fanout capability is high
c) It creates more noise
d) It is slow
e) none of the above

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

22. At the time of invention, an ECL was called as __________


a) Source-coupled logic
b) Current Mode Logic
c) Current-steering logic
d) Emitter-coupled logic
e) none of the above

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

24. IIL has _____ noise immunity.


a) High
b) Low
c) Neutral
d) Nil
e) none of the above

Answer: a

25. In Integrated Injection, logic output is received through the __________


a) Emitter
b) Base
c) Collector
d) Base Emitter Junction
e) none of the above

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

28. TTL is a ____________


a) Current sinking
b) Current sourcing
c) Voltage sinking
d) Voltage sourcing
e) none of the above

Answer: a

29. To increase fan-out of the gate in DTL ___________


a) An additional capacitor may be used
b) An additional resister may be used
c) An additional transistor and diode may be used
d) Only an additional diode may be used
e) none of the above

Answer: c

30. A disadvantage of DTL is ___________


a) The input transistor to the resister
b) The input resister to the transistor
c) The increased fan-in
d) The increased fan-out
e) none of the above
Answer: b
Multiple Choice Questions(MCQ’s)

Subject: Python Programming

Subject Code: KNC402

1|P a g e
PYTHON PROGRAMING (KNC – 402)

UNIT 1
 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Python was developed by


A. Guido van Rossum
B. James Gosling
C. Dennis Ritchie
D. Bjarne Stroustrup

2. Python was developed in which year?


A. 1972
B. 1995
C. 1989
D. 1981

3. Python is written in which language?


A. C
B. C++
C. Java
D. None of the above

4. What is the extension of python file?


A. .p
B. .py
C. .python
D. None of the above

5. Python is Object Oriented Programming Language.


A. True
B. False
C. Neither true nor false
D. None of the above

6. Python 3.0 is released in which year?


A. 2000
B. 2008
C. 2011
D. 2016

7. Which of the following statements is true?


A. Python is a high level programming language.
B. Python is an interpreted language.
C. Python is an object-oriented language
D. All of the above

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

9. By the use of which character, single line is made comment in Python?


A. *
B. @
C. #
D. !

10. What is a python file with .py extension called?


A. package
B. module
C. directory
D. None of the above

11. Which of the following statements are correct?


(i) Python is a high level programming language.
(ii) Python is an interpreted language.
(iii) Python is a compiled language.
(iv) Python program is compiled before it is interpreted.
A. i, ii
B. i, iv
C. ii, iii
D. ii, iv

12. Which of the following is incorrect variable name in Python?


A. variable_1
B. variable1
C. 1variable
D. _variable

13. Is Python case sensitive when dealing with identifiers?


a) yes
b) no
c) machine dependent
d) none of the mentioned

14. What is the maximum possible length of an identifier?


a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned

15. Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned

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

18. Which of the following is not a keyword?


a) eval
b) assert
c) nonlocal
d) pass

19. All keywords in Python are in _________


a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

20. Which of the following is true for variable names in Python?


a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special characters allowed
d) none of the mentioned

21. Which of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000

22. Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on

23. Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class

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

25. What will be the output of the following Python code?

>>>str="hello"
>>>str[:2]

a) he
b) lo
c) olleh
d) hello

26. Which of the following will run without errors?


a) round(45.8)
b) round(6352.898,2,5)
c) round()
d) round(7463.123,2,1)

27. What is the return type of function id?


a) int
b) float
c) bool
d) dict

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

31. What data type is the object below?


L = [1, 23, 'hello', 1]
a) list
b) dictionary
c) array
d) tuple

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

33. Which of the following results in a SyntaxError?


a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’

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

36. Select all options that print.


hello-how-are-you

a) print(‘hello’, ‘how’, ‘are’, ‘you’)

6|P a g e
b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)

37. What is the return value of trunc()?


a) int
b) bool
c) float
d) None

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

39. If we change one data type to another, then it is called


a) Type conversion
b) Type casting
c) Both of the above
d) None of the above

40. What is list data type in Python ?


a) collection of integer number
b) collection of string
c) collection of same data type
d) collection of different data type

41. What is type casting in python ?


a) declaration of data type
b) destroy data type
c) Change data type property
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

44. Which of the following is not the data type in python ?


a) List
b) Tuple
c) Set
d) Class

45. Which of the following is the data type possible in python?

7|P a g e
a) int
b) list
c) dictionary
d) All of the above

46. Which of the following is the example of the type casting ?


a) int(2)
b) str(2)
c) str(list)
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

MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which is the correct operator for power(xy)?


a) X^y
b) X**y
c) X^^y
d) None of the mentioned

2. Which one of these is floor division?


a) /
b) //
c) %
d) None of the mentioned

3. 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

4. What is the answer to this expression, 22 % 3 is?


a) 7
b) 1
c) 0
d) 5

8|P a g e
5. Mathematical operations can be performed on a string.
a) True
b) False

6. 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

7. What is the output of this expression, 3*1**3?


a) 27
b) 9
c) 3
d) 1

8. 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

9. The expression Int(x) implies that the variable x is converted to integer.


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

11. What is the output of print 0.1 + 0.2 == 0.3?


a) True
b) False
c) Machine dependent
d) Error

12. 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

13. What is the type of inf?


a) Boolean
b) Integer
c) Float
d) Complex
14. What does ~4 evaluate to?
a) -5
b) -4
c) -3
d) +3

9|P a g e
15. What does ~~~~~~5 evaluate to?
a) +5
b) -11
c) +11
d) -5

16. Which of the following is incorrect?


a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964

17. What is the result of cmp(3, 1)?


a) 1
b) 0
c) True
d) False

18. Which of the following is incorrect?


a) float(‘inf’)
b) float(‘nan’)
c) float(’56’+’78’)
d) float(’12+34′)

19. What is the result of round(0.5) – round(-0.5)?


a) 1.0
b) 2.0
c) 0.0
d) Value depends on Python version

20. What does 3 ^ 4 evaluate to?


a) 81
b) 12
c) 0.75
d) 7

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

22. What will be the output of the following Python expression?


bin(29)
a) ‘0b10111’
b) ‘0b11101’
c) ‘0b11111’
d) ‘0b11011’

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

25. Which of the following represents the bitwise XOR operator?


a) &
b) ^
c) |
d) !

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

27. What will be the output of the following Python expression?


4^12
a) 2
b) 4
c) 8
d) 12

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

29. What will be the output of the following Python expression?

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

31. What will be the value of the following Python expression?


4+3%5
a) 4
b) 7
c) 2
d) 0

32. Evaluate the expression given below if A = 16 and B = 15.


A % B // A
a) 0.0
b) 0
c) 1.0
d) 1

33. Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **

34. 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

35. What is the value of the following expression?


2+4.00, 2**4.0
a) (6.0, 16.0)
b) (6.00, 16.00)
c) (6, 16)
d) (6.00, 16.0)

36. Which of the following is the truncation division operator?


a) /

12 | P a g e
b) %
c) //
d) |

37. 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

38. What is the value of the following expression?


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)

39. What is the value of the following expression?


float(22//3+3/3)
a) 8
b) 8.0
c) 8.3
d) 8.33

40. What will be the output of the following Python expression?


print(4.00/(2.0+2.0))
a) Error
b) 1.0
c) 1.00
d) 1

41. What will be the value of X in the following Python expression?


X = 2+9*((3*12)-8)/10
a) 30.0
b) 30.8
c) 28.4
d) 27.2

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) %

45. What will be the value of the following Python expression?


float(4+int(2.39)%2)
a) 5.0
b) 5
c) 4.0
d) 4

46. 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

47. Which of the following expressions results in an error?


a) float(‘10’)
b) int(‘10’)
c) float(’10.8’)
d) int(’10.8’)

48. What will be the value of the following Python expression?


4+2**5//10
a) 3
b) 7
c) 77
d) 0

49. The expression 2**2**3 is evaluates as: (2**2)**3.


a) True
b) False

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

1. In Python, a decision can be made by using if else statement.


a. True b. False

2. Checking multiple conditions in Python requires elif statements.


a. True b. False

3. If the condition is evaluated to true, the statement(s) of if block will be


executed, otherwise the statement(s) in else block(if else is specified) will be
executed.
a. True b. False

4. What kind of statement is IF statement?


a. Concurrent b. Sequential
c. Assignment d. Selected assignment

5. Which one of the following is a valid Python if statement :

a. if (a => 22) b. if(a>=2)


c. if a>=2 : d. if a >= 22
6. What keyword would you use to add an alternative condition to an if
statement?
a. Else if b. Elseif
c. Elif d. None of the above

7. Can we write if/else into one line in python?

a. Yes
b. No
c. if/else not used in python
d. None of the above

8. In a Python program, a control structure:

a. Defines program-specific data structures


b. Directs the order of execution of the statements in the program
c. Dictates what happens before the program starts and after it terminates
d. None of the above
9. What will be output of this expression:
‘p’ + ‘q’ if ‘12’.isdigit() else ‘r’ + ‘s’

16 | P a g e
a. pq
b. rs
c. pqrs
d. pq12

10. Which statement will check if a is equal to b?

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

13. What does the following code print to the console?


name = "maria"
if name == "melissa":
print("usa")
elif name == "mary":
print("ireland")
else:
print("colombia")

17 | P a g e
a. usa b. ireland
c.colombia d. None of the above

14. What does the following code print to the console?


if "cat" == "dog":
print("prrrr")
else:
print("ruff")
a. ruff b. ruf
c. prrrr d. prr

15. What does the following code print to the console?


hair_color = "blue"
if 3 > 2:
if hair_color == "black":
print("You rock!")
else:
print("Boring")
a. blue b. black
c. You rock! d. Boring
16. What does the following code print to the console?
if True:
print(101)
else:
print(202)
a. true b. false
c. 101 d. 202

17. What does the following code print to the console?


if False:
print("Nissan")
elif True:
print("Ford")
elif True:
print("BMW")
else:

18 | P a g e
print("Audi")
a. Nissan b. Ford
c. BMW d. Audi

18. What does the following code print to the console?


if 1:
print("1 is truthy!")
else:
print("???")
a. 1 is truthy! b. ???
c. Invalid d. None of the above

19. What does the following code print to the console?


if 0:
print("huh?")
else:
print("0 is falsy!")
a. o b. Huh
c. 0 is falsy! d. None of the above

20. What does the following code print to the console?


if 88 > 100:
print("cardio")
a. 88 b. 100
b. cardio d. Nothing is printed..

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

2. for loop in python are work on


A. range
B. iteration
C. Both of the above
D. None of the above

3. For loop in python is


A. Entry control loop
B. Exit control loop
C. Simple loop
D. None of the above

4. for i in range(-3), how many times this loop will run ?


A. 0
B. 1
C. Infinite
D. Error

5. for i in [1,2,3]:, how many times a loop run ?


A. 0
B. 1
C. 2
D. 3
6. How many times it will print the statement ?, for i in range(100): print(i)
A. 101
B. 99
C. 100
D. 0

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

8. What is the value of i after the for loop ?, for i in range(4):break


A. 1
B. 2
C. 3
D. 0

9. What is the output of the following?


x = 'abcd'
for i in x:
print(i.upper())

20 | P a g e
A. a b c d
B. A B C D
C. a B C D
D. error

10. What is the output of the following?


x = 'abcd'
for i in range(len(x)):
x[i].upper()
print (x)
A. abcd
B. ABCD
C. error
D. none of the mentioned

11. What is the output of the following?


d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.values():
print(x)
A. 0 1 2
B. a b c
C. 0 a 1 b 2 c
D. none of the mentioned

12. What will be the output of the following Python code?


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

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

14.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

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

16. What will be the output of the following Python code?


for i in range(2.0):
print(i)
A. 0.0 1.0
B. 0 1
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

18. What will be the output of the following Python code?


for i in range(int(2.0)):
print(i)

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

21. What will be the output of the following Python code?


for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")

A. 0 1 2 3 4 Here
B. 0 1 2 3 4 5 Here
C. 0 1 2 3 4
D. 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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. In which of the following loop in python, we can check the condition ?


A. for loop
B. while loop
C. do while loop
D. None of the above

2. It is possible to create a loop using goto statement in python ?


A. Yes
B. No
C. Sometimes
D. None of the above

3. To break the infinite loop , which keyword we use ?


A. continue
B. break
C. exit
D. None of the above

4. While(0), how many times a loop run ?


A. 0

23 | P a g e
B. 1
C. 3
D. infinite

5. while(1==3):, how many times a loop run ?


A. 0
B. 1
C. 3
D. infinite

6. What is the output of the following?


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

7. What is the output of the following?


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

8. What will be the output of the following Python code?


i=1
while True:
if i%0O7 == 0:
break
print(i)
i += 1

A. 123456
B. 1234567
C. error
D. none of the mentioned

9. What will be the output of the following Python code?


True = False
while True:
print(True)
break

A. True

24 | P a g e
B. False
C. None
D. none of the mentioned

10. 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. 0120
B. 012
C. None
D. none of the mentioned

11. 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

12. 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 a a a
C. i i i i i i
D. None of the mentioned

13. 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

14. What will be the output of the following Python code?

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

15. What will be the output of the following Python code?


i = 5while True: if i%O.11 == 0: break print(i) i += 1

A. 5 6 7 8 9 10
B. 5 6 7 8
C. 5 6
D. Error

16. What will be the output of the following Python code?


i=5
while True: if i%O.9 == 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

17. 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 ....

18. 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

19. What will be the output of the following Python code?


i = 1while False:
if i%2 == 0:
break
print(i)
i += 2

26 | P a g e
A. 1
B. 1 3 5 7 ...
C. 1 2 3 4 ....
D. none of the mentioned

20. What will be the output of the following Python code?


True = False
while True:
print(True)
Break

A. true
B. false
C. error
D. none of the mentioned

21. 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

22. 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

23. 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

27 | P a g e
B. a
C. no output
D. error

ANSWERS :

1. B 2.B 3.B 4.A 5.A 6.B 7.A 8.A 9.D(SyntaxError, True


is a keyword and it’s value cannot be changed.) 10.B 11.D 12.A 13.C 14.A
15.B 16.D 17.D 18.B 19.D 20.D 21.B 22.B 23.B

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which of the following functions is a built-in function in python?


A. seed()
B. sqrt()
C. factorial()
D. print()

2. What will be the output of the following Python expression?


round(4.576)

A. 4.5
B. 5
C. 4
D. 4.6

3. The function pow(x,y,z) is evaluated as:

A. (x**y)**z
B. (x**y)/z
C. (x**y)%z
D. (x**y)*z

4. What will be the output of the following Python function?


all([2,4,0,6])

A. Error
B. True
C. False
D. 0

5. What will be the output of the following Python function?


any([2>8, 4>2, 1>2])

A. Error

28 | P a g e
B. True
C. False
D. 4>2

6. What will be the output of the following Python function?


import math
abs(math.sqrt(25))

A. Error
B. -5
C. 5
D. 5.0

7. What will be the output of the following Python function?


sum(2,4,6)sum([1,2,3])

A. Error,6
B. 12, Error
C. 12,6
D. Error, Error

8. What will be the output of the following Python function?


min(max(False,-3,-4), 2,7)

A. 2
B. False
C. -3
D. -4

9. What will be the output of the following Python functions?


chr(‘97’)chr(97)

A. a Error
B. ‘a’ Error
C. Error a
D. Error Error

10. What will be the output of the following Python function?


complex(1+2j)

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)

12. What will be the output of the following Python function?


list(enumerate([2, 3]))

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()

14. Which of the following functions accepts only integers as arguments?

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()

16. What will be the output of the following Python function?


hex(15)

A. f
B. OxF
C. OXf
D. Oxf

17. What will be the output of the following Python function?


len(["hello",2, 4, 6])

A. 4
B. 3
C. Error
D. 6

18. Which of the following is the use of function in python?

A. functions are reusable pieces of programs


B. functions don’t provide better modularity for your application
C. you can’t also create your own functions
D. all of the mentioned

19. Which keyword is used for function?


A. Fun

30 | P a g e
B. Define
C. Def
D. Function

20. What will be the output of the following Python code?

def sayHello():
print('Hello World!')

sayHello()
sayHello()

A. Hello World! Hello World!


B. 'Hello World!' 'Hello World!'
C. Hello Hello
D. None of the mentioned

21. What will be the output of the following Python code?


def printMax(a, b):
if a > b:
print(a, 'is maximum')
elif a == b:
print(a, 'is equal to', b)
else:
print(b, 'is maximum')
printMax(3, 4)

A. 3
B. 4
C. 4 is maximum
D. None of the mentioned

22. What will be the output of the following Python code?


x = 50
def func(x):
print('x is', x)
x=2
print('Changed local x to', x)
func(x)
print('x is now', x)

A. x is now 50
B. x is now 2
C. x is now 100
D. None of the mentioned

23. What will be the output of the following Python code?

def say(message, times = 1):


print(message * times)

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

24. What will be the output of the following Python code?

def func(a, b=5, c=10):


print('a is', a, 'and b is', b, 'and c is', c)
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)

A. a is 7 and b is 3 and c is 10 a is 25 and b is 5 and c is 24 a is 5 and b is 100 and c is 50


B. a is 3 and b is 7 and c is 10 a is 5 and b is 25 and c is 24 a is 50 and b is 100 and c is 5
C. a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50
D. None of the mentioned

25. Which of the following is a feature of DocString?


A. Provide a convenient way of associating documentation with Python modules, functions, c
classes,and methods
B. All functions should have a docstring
C. Docstrings can be accessed by the __doc__ attribute on objects
D. All of the mentioned

26. Which are the advantages of functions in python?


A. Reducing duplication of code
B. Decomposing complex problems into simpler pieces
C. Improving clarity of the code
D. All of the mentioned

27. What are the two main types of functions?


A. Custom function
B. Built-in function & User defined function
C. User function
D. System function

28. Where is function defined?


A. Module
B. Class
C. Another function
D. All of the mentioned

29. What is called when a function is defined inside a class?


A. Module
B. Class
C. Another function
D. Method

30. Which of the following is the use of id() function in python?

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

31. Which of the following refers to mathematical function?


A. sqrt
B. rhombus
C. add
D. Rhombus

32. What will be the output of the following Python code?

def cube(x):

return x * x * x

x = cube(3)
print x

A. 9
B. 3
C. 27
D. 30

33. What will be the output of the following Python code?

def C2F(c):

return c * 9/5 + 32

print C2F(100)

print C2F(0)

A. 212
32
B. 314
24
C. 567
98
D. None of the mentioned

34. What will be the output of the following Python code?

def power(x, y=2):


r=1
for i in range(y):
r=r*x
return r
print power(3)
print power(3, 3)

33 | P a g e
A. 212
32
B. 9
27
C. 567
98
D. None of the mentioned.

35. What will be the output of the following Python code?


def foo(k):
k[0] = 1
q = [0]
foo(q)print(q)
A. [0]
B. [1]
C. [1, 0]
D. [0, 1]

36. How are keyword arguments specified in the function heading?


A. one-star followed by a valid identifier
B. one underscore followed by a valid identifier
C. two stars followed by a valid identifier
D. two underscores followed by a valid identifier

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

38. What will be the output of the following Python code?


def foo(fname, val):
print(fname(val))
foo(max, [1, 2, 3])
foo(min, [1, 2, 3])
A. 3 1
B. 1 3
C. error
D. none of the mentioned

39. What will be the output of the following Python code?


def foo():
return total + 1
total = 0print(foo())
A. 0
B. 1
C. error
D. none of the mentioned

40. What will be the output of the following Python code?


def foo():
total += 1

34 | P a g e
return total
total = 0print(foo())
A. 0
B. 1
C. error
D. none of the mentioned

41. What will be the output of the following Python code?


def foo(k):
k = [1]
q = [0]
foo(q)print(q)
A. [0]
B. [1]
C. [1, 0]
D. [0, 1]

42. What will be the output of the following Python code?


def f1():
x=15
print(x)
x=12
f1()
A. Error
B. 12
C. 15
D. 1512

43. What will be the output of the following Python code?


def f1():
x=100
print(x)
x=+1
f1()
A. Error
B. 100
C. 101
D. 99

44. What will be the output of the following Python code?


def san(x):
print(x+1)
x=-2
x=4
san(12)
A. 13
B. 10
C. 2
D. 5

45. What will be the output of the following Python code?


def f1():
global x

35 | P a g e
x+=1
print(x)
x=12print("x")
A. Error
B. 13
C. 13
x
D. X

46. What will be the output of the following Python code?


def f1(x):
global x
x+=1
print(x)
f1(15)print("hello")
A. error
B. hello
C. 16
D. 16
hello

47. What will be the output of the following Python code?


x=12def f1(a,b=x):
print(a,b)
x=15
f1(4)
A. Error
B. 12 4
C. 4 12
D. 4 15

48. What will be the output of the following Python code?


def f1(a,b=[]):
b.append(a)
return bprint(f1(2,[3,4]))
A. [3,2,4]
B. [2,3,4]
C. Error
D. [3,4,2]

49. What will be the output of the following Python code?


def f(p, q, r):
global s
p = 10
q = 20
r = 30
s = 40
print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)
A. 1 2 3 4
B. 5 10 15 4
C. 10 20 30 40

36 | P a g e
D. 5 10 15 40

50. What will be the output of the following Python code?


def f(x):
print("outer")
def f1(a):
print("inner")
print(a,x)
f(3)
f1(1)
A. outer
error
B. inner
error
C. outer
inner
D. error

51. What will be the output of the following Python code?


x = 5 def f1():
global x
x = 4def f2(a,b):
global x
return a+b+x
f1()
total = f2(1,2)print(total)
A. Error
B. 7
C. 8
D. 15

52. What will be the output of the following Python code?


x=100def f1():
global x
x=90def f2():
global x
x=80print(x)
A. 100
B. 90
C. 80
D. Error

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

55. What will be the output of the following Python code?


x=1def cg():
global x
x=x+1
cg()
x
A. 2
B. 1
C. 0
D. Error

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 :

1.D 2.B 3.A 4.C 5.B 6.D 7.A 8.B 9.C


10.D 11.B 12.C 13.C 14.C 15.D 16.D 17.A
18.A 19.C 20.A 21.C 22.A 23.A 24.C 25.D
26.D 27.B 28.D 29.D 30.A 31.A 32.C 33.A 34.B
35.B 36.C 37.C 38.A 39.B 40.C 41.A 42.C 43.B 44.A
45.D 46.A 47.C 48.D 49.C 50.A 51.B 52.A 53.C 54.C
55.A 56.D

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. What will be the output of the following Python statement?


"a"+"bc"
a)a
b)bc
c)bca
d) abc
Answer: d

2. What will be the output of the following Python statement?

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

4. What will be the output of the following Python code?


>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]

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

12. What will be the output of the following Python code?


>>>max("what are you")
a) error
b) u
c) t
d) y
Answer: d
13. Given a string example=”hello” what is the output of example.count(‘l’)?
a)2
b)1
c) None
d) 0
Answer: a
14. What will be the output of the following Python code?
>>>example = "helle"
>>>example.find("e")
a) Error
b) -1
c) 1
d) 0
Answer: c
15. What will be the output of the following Python code?
>>>example = "helle"
>>>example.rfind("e")
a) -1
b) 4
c) 3
d) 1
Answer: b
16. What will be the output of the following Python code?

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)

29. What function do you use to read a string?


a) input(“Enter a string”)
b) eval(input(“Enter a string”))
c) enter(“Enter a string”)
d) eval(enter(“Enter a string”))

30. What will be the output of the following Python code?


print("abc DEF".capitalize())
a) abc def
b) ABC DEF
c) Abc def
d) Abc Def

31. What will be the output of the following Python code?


print("xyyzxyzxzxyy".count('yy'))
a) 2
b) 0
c) error
d) none of the mentioned

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

35. What will be the output of the following Python code?


print("Hello {0} and {1}".format('foo', 'bin'))
a) Hello foo and bin
b) Hello {0} and {1} foo bin
c) Error
d) Hello 0 and 1
36. What will be the output of the following Python code?
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))
a) Hello foo and bin
b) Hello {name1} and {name2}
c) Error
d) Hello and

37. What will be the output of the following Python code?


print('ab12'.isalnum())
a) True
b) False
c) None
d) Error

38. What will be the output of the following Python code?


print('a B'.isalpha())
a) True
b) False
c) None
d) Error
Explanation: Space is not a letter.
39. What will be the output of the following Python code snippet?
print('0xa'.isdigit())
a) True
b) False
c) None

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

1. Which of the following is a Python tuple?


a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {}

2.Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))

3.What will be the output of the following Python code?


>>>t=(1,2,4,3)
>>>t[1:3]
a)(1,2)
b)(1,2,4)
c)(2,4)
d) (2, 4, 3)

4. What will be the output of the following Python code?


t=(1,2,4,3)
t[1:-1]
a)(1,2)
b)(1,2,4)
c)(2,4)
d) (2, 4, 3)

5. What will be the output of the following Python code?


t = (1, 2, 4, 3, 8, 9)
[t[i] for i in range(0, len(t), 2)]
a)[2,3,9]
b)[1,2,4,3,8,9]
c)[1,4,8]
d) (1, 4, 8)

6. What will be the output of the following Python code?


d = {"john":40, "peter":45}
d["john"]
a)40
b)45
c)“john”

45 | P a g e
d) “peter”

7. What will be the output of the following Python code?


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]

8. What will be the output of the following Python code?


t1 = (1, 2, 4, 3)
t2 = (1, 2, 3, 4)
t1 < t2
a)True
b)False
c)Error
d) None

9. What will be the output of the following Python code?


my_tuple = (1, 2, 3, 4)
my_tuple.append( (5, 6, 7) )
print len(my_tuple)
a)1
b)2
c)5
d) Error

10. What is the data type of (1)?a)Tuple


b)Integer
c)List
d) Both tuple and integer

11. If a=(1,2,3,4), a[1:-1] is _________


a)Error, tuple slicing doesn’t exist
b)[2,3]
c)(2,3,4)
d) (2,3)

12. What will be the output of the following Python code?


a=(1,2,(4,5))
b=(1,2,(3,4))
a<b
a) False
b) True
c) Error, < operator is not valid for tuples

46 | P a g e
d) Error, < operator is valid for tuples but not if there are sub-tuples

13. What will be the output of the following Python code?


a=("Check")*3
a
a)(‘Check’,’Check’,’Check’)
b)* Operator not valid for tuples
c)(‘CheckCheckCheck’)
d) Syntax error

14. What will be the output of the following Python code?


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)
d) Error as tuple is immutable

15. What will be the output of the following Python code?


a=(2,3,4)
sum(a,3)
a) Too many arguments for sum() method
b) The method sum() doesn’t exist for tuples
c)12
d) 9

16. Is the following Python code valid?


a=(1,2,3,4)
del a
a)No because tuple is immutable
b)Yes, first element in the tuple is deleted
c)Yes, the entire tuple is deleted
d) No, invalid syntax for del method

17. What type of data is: a=[(1,1),(2,4),(3,9)]?


a) Array of tuples
b) List of tuples
c) Tuples of lists
d) Invalid type

18. What will be the output of the following Python code?


a=(0,1,2,3,4)
b=slice(0,2)
a[b]
a)Invalid syntax for slicing
b)[0,2]

47 | P a g e
c)(0,1)
d) (0,2)

19. Is the following Python code valid?


a=(1,2,3)
b=('A','B','C')
c=tuple(zip(a,b))
a)Yes, c will be ((1, ‘A’), (2, ‘B’), (3, ‘C’))
b)Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
c)No because tuples are immutable
d) No because the syntax for zip function isn’t valid

20. Is the following Python code valid?


a,b,c=1,2,3
a,b,c
a)Yes,[1,2,3] is printed
b)No,invalid syntax
c)Yes,(1,2,3) is printed
d) 1 is printed

21. Is the following Python code valid?


a,b=1,2,3
a)Yes, this is an example of tuple unpacking. a=1 and b=2
b) Yes, this is an example of tuple unpacking. a=(1,2) and b=3
c) No, too many values to unpack
d) Yes, this is an example of tuple unpacking. a=1 and b=(2,3)

22. What will be the output of the following Python code?


a=(1,2)
b=(3,4)
c=a+b
c
a)(4,6)
b)(1,2,3,4)
c)Error as tuples are immutable
d) None

23. What will be the output of the following Python code?


a,b=6,7
a,b=b,a
a,b
a)(6,7)
b)Invalid syntax
c)(7,6)
d) Nothing is printed

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

25. What will be the output of the following Python code?


a=(2,3,1,5)
a.sort()
a
a)(1,2,3,5)
b)(2,3,1,5)
c)None
d) Error, tuple has no attribute sort

26. Is the following Python code valid?


a=(1,2,3)
b=a.update(4,)
a)Yes, a=(1,2,3,4) and b=(1,2,3,4)
b)Yes, a=(1,2,3) and b=(1,2,3,4)
c)No because tuples are immutable
d) No because wrong syntax for update() method

27. What will be the output of the following Python code?


a=[(2,4),(1,2),(3,9)]
a.sort()
a
a)[(1, 2), (2, 4), (3, 9)]
b)[(2,4),(1,2),(3,9)]
c)Error because tuples are immutable
d) Error, tuple has no sort attribute

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

1. Which of the following commands will create a list?


a)list1=list()
b)list1=[]
c)list1=list([1,2,3])
d) all of the mentioned

2. What is the output when we execute list(“hello”)?


a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) [‘hello’]
c) [‘llo’]
d) [‘olleh’]

3. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?


a) 5
b) 4
c) None
d) Error

4. Suppose list1 is [2445,133,12454,123], what is max(list1)?


a) 2445
b) 133
c) 12454
d) 123

5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?


a) 3
b) 5
c) 25
d) 1

6. Suppose list1 is [1, 5, 9], what is sum(list1)?


a) 1
b) 9
c) 15
d) Error

7. To shuffle the list(say list1) what function do we use?


a) list1.shuffle()
b) shuffle(list1)
c) random.shuffle(list1)
d) random.shuffleList(list1)

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]

11. What will be the output of the following Python code?


>>>names = ['Amir', 'Bear', 'Charlton', 'Daman']
>>>print(names[-1][-1])
A
b) Daman
c) Error
d) n

12. Suppose list1 is [1, 3, 2], What is list1 * 2?


a) [2, 6, 4]
b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2]
d) [1, 3, 2, 3, 2, 1]

13. What will be the output of the following Python code?


>>>list1 = [11, 2, 23]
>>>list2 = [11, 2, 2]
>>>list1 < list2 is
True
b) False
c) Error
d) None

14. To add a new element to a list we use which command?


a) list1.add(5)
b) list1.append(5)
c) list1.addLast(5)
d) list1.addEnd(5)

15. To insert 5 to the third position in list1, we use which command?


a) list1.insert(3, 5)
b) list1.insert(2, 5)
c) list1.add(3, 5)
d) list1.append(3, 5)

16. To remove string “hello” from list1, we use which command?


a) list1.remove(“hello”)
b) list1.remove(hello)
c) list1.removeAll(“hello”)
d) list1.removeOne(“hello”)

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

18. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?


a) 0
b) 4
c) 1
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]

23. What will be the output of the following Python code?


>>>"Welcome to Python".split()
a) [“Welcome”, “to”, “Python”]
b) (“Welcome”, “to”, “Python”)
c) {“Welcome”, “to”, “Python”}
d) “Welcome”, “to”, “Python”

24. What will be the output of the following Python code?


>>>list("a#b#c#d".split('#'))
a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘a b c d’]
c) [‘a#b#c#d’]
d) [‘abcd’]

25. What will be the output of the following Python code?


myList = [1, 5, 5, 5, 5, 1]
max = myList[0]

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

26. What will be the output of the following Python code?


>>>list1 = [1, 3]
>>>list2 = list1
>>>list1[0] = 4
>>>print(list2)
[1, 3]
b) [4, 3]
c) [1, 4]
d) [1, 3, 4]

27. What will be the output of the following Python code?


names1 = ['Amir', 'Bala', 'Chales']
if 'amir' in names1:
print(1)
else:
print(2)
a) None
b) 1
c) 2
d) Error

28. What will be the output of the following Python code?


numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print(len(numbers))
a) 4
b) 5
c) 8
d) 12

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

30. What will be the output of the following Python code?


list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
print(len(list1 + list2))
a) 2
b) 4

53 | P a g e
c) 5
d) 8

31. What will be the output of the following Python code?


matrix = [[1, 2, 3, 4],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12, 13, 14, 15]]
for i in range(0, 4):
print(matrix[i][1], end = " ")
a) 1 2 3 4
b) 4 5 6 7
c) 1 3 8 12
d) 2 5 9 13

32. What will be the output of the following Python code?


data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
print(data[1][0][0])
a) 1
b) 2
c) 4
d) 5

33. What will be the output of the following Python code?


points = [[1, 2], [3, 1.5], [0.5, 0.5]]
points.sort()
print(points)
[[1, 2], [3, 1.5], [0.5, 0.5]]
b) [[3, 1.5], [1, 2], [0.5, 0.5]]
c) [[0.5, 0.5], [1, 2], [3, 1.5]]
d) [[0.5, 0.5], [3, 1.5], [1, 2]]

34. What will be the output of the following Python code?


a=[[]]*3
a[1].append(7)
print(a)
a) Syntax error
b) [[7], [7], [7]]
c) [[7], [], []]
d) [[],7, [], []]

35. What will be the output of the following Python code?


b=[2,3,4,5]
a=list(filter(lambda x:x%2,b))
print(a)
a) [2,4]
b) [ ]
c) [3,5]
d) Invalid arguments for filter function

36. What will be the output of the following Python code?


lst=[3,4,6,1,2]
lst[1:2]=[7,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]

37. What will be the output of the following Python code?


a=[1,2,3]
b=a.append(4)print(a)
print(b)
a)[1,2,3,4]
[1,2,3,4]
b)[1, 2, 3, 4]
None
c)Syntax error
d)[1,2,3]
[1,2,3,4]

38. What will be the output of the following Python code?


a=[13,56,17]
a.append([87])
a.extend([45,67])
print(a)
a) [13, 56, 17, [87], 45, 67]
b) [13, 56, 17, 87, 45, 67]
c) [13, 56, 17, 87,[ 45, 67]]
d) [13, 56, 17, [87], [45, 67]]

39. What will be the output of the following Python code?


lst=[[1,2],[3,4]]
print(sum(lst,[]))
a) [[3],[7]]
b) [1,2,3,4]
c) Error
d) [10]

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:


a) [0, 1, 2, 3]
b) [0, 1, 2, 3, 4]
c) [0.0, 0.5, 1.0, 1.5]

55 | P a g e
d) [0.0, 0.5, 1.0, 1.5, 2.0]

2. What will be the output of the following Python code?


>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]
a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
c) [1, 2, 3, 4, 5, 6, 7, 8, 9]
d) [0, 1, 2, 1, 2, 3, 2, 3, 4]

3. How many elements are in m?


m = [[x, y] for x in range(0, 4) for y in range(0, 4)]
a) 8
b) 12
c) 16
d) 32

4. What will be the output of the following Python code snippet?


k = [print(i) for i in my_string if i not in "aeiou"]
a) prints all the vowels in my_string
b) prints all the consonants in my_string
c) prints all characters of my_string that aren’t vowels
d) prints only on executing print(k)

5. What is the output of print(k) in the following Python code snippet?

k = [print(i) for i in my_string if i not in "aeiou"]


print(k)
a) all characters of my_string that aren’t vowels
b) a list of Nones
c) list of Trues
d) list of Falses

6. What will be the output of the following Python code snippet?

my_string = "hello world"


k = [(i.upper(), len(i)) for i in my_string]
print(k)
a) [(‘HELLO’, 5), (‘WORLD’, 5)]
b) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1),
(‘D’, 1)]
c) [(‘HELLO WORLD’, 11)]
d) none of the mentioned

56 | P a g e
7. What will be the output of the following Python code snippet?

x = [i**+1 for i in range(3)]; print(x);


a) [0, 1, 2]
b) [1, 2, 5]
c) error, **+ is not a valid operator
d) error, ‘;’ is not allowed

8. What will be the output of the following Python code snippet?

print([i.lower() for i in "HELLO"])


a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
b) ‘hello’
c) [‘hello’]
d) hello

9. What will be the output of the following Python code snippet?

print([if i%2==0: i; else: i+1; for i in range(4)])


a) [0, 2, 2, 4]
b) [1, 1, 3, 3]
c) error
d) none of the mentioned

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

11. What will be the output of the following Python code?

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]

15. What will be the output of the following Python code?

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)]

17. Write a list comprehension to produce the list: [1, 2, 4, 8, 16……212].


a) [(2**x) for x in range(0, 13)]
b) [(x**2) for x in range(1, 13)]
c) [(2**x) for x in range(1, 13)]
d) [(x**2) for x in range(0, 13)]

58 | P a g e
18. What will be the output of the following Python list comprehension?

[j for i in range(2,8) for j in range(i*2, 50, i)]


a) A list of prime numbers up to 50
b) A list of numbers divisible by 2, up to 50
c) A list of non prime numbers, up to 50
d) Error

19. What will be the output of the following Python code?

l=["good", "oh!", "excellent!", "#450"]


[n for n in l if n.isalpha() or n.isdigit()]
a) [‘good’, ‘oh’, ‘excellent’, ‘450’ ]
b) [‘good’]
c) [‘good’, ‘#450’]
d) [‘oh!’, ‘excellent!’, ‘#450’]

20. Write a list comprehension equivalent for the Python code shown below.

for i in range(1, 101):


if int(i*0.5)==i*0.5:
print(i)
a) [i for i in range(1, 100) if int(i*0.5)==(i*0.5)]
b) [i for i in range(1, 101) if int(i*0.5)==(i*0.5)]
c) [i for i in range(1, 101) if int(i*0.5)=(i*0.5)]
d) [i for i in range(1, 100) if int(i*0.5)=(i*0.5)]

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which of these about a set is not true?


a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type

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}

3. What will be the output of the following Python code?


nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
a) 7
b) Error, invalid syntax for formation of set
c) 4
d) 8

4. Which of the following statements is used to create an empty set?


a) {}
b) set()
c) []
d) ( )

5. What will be the output of the following Python code?


a={5,4}
b={1,2,4,5}
a<b
a) {1,2}
b) True
c) False
d) Invalid operation
a<b returns True if a is a proper subset of b.

6. If a={5,6,7,8}, which of the following statements is false?


a) print(len(a))
b) print(min(a))
c) a.remove(5)
d) a[2]=45
7. If a={5,6,7}, what happens when a.add(5) is executed?
a) a={5,5,6,7}
b) a={5,6,7}
c) Error as there is no add function for set data type
d) Error as 5 already exists in the set

8. What will be the output of the following Python code?


a={4,5,6}
b={2,8,6}
a+b
a) {4,5,6,2,8}
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) Error as the duplicate item 6 is present in both sets

9. What will be the output of the following Python code?


a={4,5,6}
b={2,8,6}
a-b
a) {4,5}
b) {6}

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

10. What will be the output of the following Python code?


a={5,6,7,8}
b={7,8,10,11}
a^b
a) {5,6,7,8,10,11}
b) {7,8}
c) Error as unsupported operand type of set data type
d) {5,6,10,11}
^ operator returns a set of elements in set A or set B, but not in both (symmetric difference).

11. What will be the output of the following Python code?


s={5,6}
s*3
a) Error as unsupported operand type for set data type
b) {5,6,5,6,5,6}
c) {5,6}
d) Error as multiplication creates duplicate elements which isn’t allowed
The multiplication operator isn’t valid for the set data type.

12. What will be the output of the following Python code?


a={3,4,5}
b={5,6,7}
a|b
a) Invalidoperation
b) {3,4,5,6,7}
c) {5}
d) {3,4,6,7}

13. Is the following Python code valid?


a={3,4,{7,5}}
print(a[2][0])
a) Yes, 7 is printed
b) Error, elements of a set can’t be printed
c) Error, subsets aren’t allowed
d) Yes, {7,5} is printed

14. Which of these about a frozenset is not true?


a)Mutable data type
b)Allows duplicate values
c)Data type with unordered values
d) Immutable data type

15. What will be the output of the following Python code?


a={3,4,5}
a.update([1,2,3])
a
a) Error, no method called update for set data type
b) {1, 2, 3, 4, 5}
c) Error, list can’t be added to set

61 | P a g e
d) Error, duplicate item present in list

16. What will be the output of the following Python code?


>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a
a) {2,3}
b) Error, duplicate item present in list
c) Error, no method called intersection_update for set data type
d) {1,4,5}

17. What will be the output of the following Python code?


>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> a
a) {1,2,3}
b) Error, copying of sets isn’t allowed
c) {1,2}
d) Error, invalid syntax for remove

18. What will be the output of the following Python code?


>>> a={1,2,3}
>>> b=a.add(4)
>>> b
a) 0
b) {1,2,3,4}
c) {1,2,3}
d) Nothing is printed

19. What will be the output of the following Python code?


>>> a={5,6,7}
>>> sum(a,5)
a) 5
b) 23
c) 18
d) Invalid syntax for sum method, too many arguments

20. What will be the output of the following Python code?


>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}
a) {2,4,6}
b) Error, set comprehensions aren’t allowed
c) {8,2,10,4,6}
d) {8,10}
Set comprehensions are allowed

21. What will be the output of the following Python code?


>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)
a) 8
b) Error, unsupported operand ‘+’ for sets

62 | P a g e
c) 6
d) Nothing is displayed

22. What will be the output of the following Python code?


a={1,2,3}
b={1,2,3}
c=a.issubset(b)
print(c)
a) True
b) Error, no method called issubset() exists
c) Syntax error for issubset() method
d) False

23. Is the following Python code valid?


a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)
a) False
b) True
c) Syntax error for issuperset() method
d) Error, no method called issuperset()

24.Set makes use of __________


Dictionary makes use of ____________
a) keys, keys
b) key values, keys
c) keys, key values
d) key values, key values

25. What will be the output of the following Python code?


s={2, 5, 6, 6, 7}
s
a) {2,5,7}
b) {2,5,6,7}
c) {2,5,6,6,7}
d) Error

26. Which of the following functions cannot be used on heterogeneous sets?


a) pop
b) remove
c) update
d) sum

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which of the following statements create a dictionary?


a) d={}
b) d={“john”:40,“peter”:45}
c) d={40:”john”,45:”peter”}
d) All of the mentioned

2. What will be the output of the following Python code snippet?


d = {"john":40, "peter":45}
a) “john”,40,45,and“peter”
b) “john”and“peter”
c) 40and45
d) d = (40:”john”, 45:”peter”)

3. 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

4. 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

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

6. What will be the output of the following Python code snippet?


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”)
c) del d[“john”]
d) del d(“john”:40)

8. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which


command do we use?
a) d.size()
b) len(d)
c) size(d)
d) d.len()

9. What will be the output of the following Python code snippet?


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)

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

11. Which of these about a dictionary is false?


a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable

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

15. What will be the output of the following Python code?


a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)
a) {1:‘A’,2:‘B’,3:‘C’}
b) Method update() doesn’t exist for dictionaries
c) {1:‘A’,2:‘B’,3:‘C’,4:‘D’,5:‘E’}
d) {4: ‘D’, 5: ‘E’}

16. What will be the output of the following Python code?


a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)
a) Error, copy() method doesn’t exist for dictionaries
b) {1:‘A’,2:‘B’,3:‘C’}
c) {1:‘A’,2:‘D’,3:‘C’}
d) “None” is printed

17. What will be the output of the following Python code?


a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
a) None
b) {None:None,None:None,None:None}
c) {1:None,2:None,3:None}
d) { }

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

19. What will be the output of the following Python code?


a={1:5,2:3,3:4}
a.pop(3)
print(a)
a) {1:5}
b) {1:5,2:3}
c) Error, syntax error for pop() method
d) {1: 5, 3: 4}

20. What will be the output of the following Python code?


a={1:5,2:3,3:4}
print(a.pop(4,9))
a) 9
b) 3
c) Too many arguments for pop() method
d) 4

21. What will be the output of the following Python code?


a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
a) 123
b) ‘A’‘B’‘C’
c) 1‘A’2‘B’3‘C’
d) Error, it should be: for i in a.items():

22. What will be the output of the following Python code?


>>> a={1:"A",2:"B",3:"C"}
>>> a.items()
a) Syntax error
b) dict_items([(‘A’),(‘B’),(‘C’)])
c) dict_items([(1,2,3)])
d) dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])

23. Which of the statements about dictionary values if false?


a) More than one key can have the same value
b) The values of the dictionary can be accessed as dict[key]
c) Values of a dictionary must be unique
d) Values of a dictionary can be a mixture of letters and numbers

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

26. What will be the output of the following Python code?


>>> a={'B':5,'A':9,'C':7}
>>> sorted(a)
a) [‘A’,’B’,’C’]
b) [‘B’,’C’,’A’]
c) [5,7,9]
d) [9,5,7]
27. What will be the output of the following Python code?
>>> a={i: i*i for i in range(6)}
>>> a
a) Dictionary comprehension doesn’t exist
b) {0:0,1:1,2:4,3:9,4:16,5:25,6:36}
c) {0:0,1:1,4:4,9:9,16:16,25:25}
d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

28. What will be the output of the following Python code?


>>> a={}
>>> a.fromkeys([1,2,3],"check")
a) Syntax error
b) {1:”check”,2:”check”,3:”check”}
c) “check”
d) {1:None,2:None,3:None}

29. What will be the output of the following Python code?


>>> b={}
>>> all(b)
a) {}
b) False
c) True
d) An exception is thrown

30. If b is a dictionary, what does any(b) do?


a) Returns True if any key of the dictionary is true
b) Returns False if dictionary is empty
c) Returns True if all keys of the dictionary are true
d) Method any() doesn’t exist for dictionary

31. What will be the output of the following Python code?


>>> a={"a":1,"b":2,"c":3}
>>> b=dict(zip(a.values(),a.keys()))
>>> b
a) {‘a’:1,‘b’:2,‘c’:3}

69 | P a g e
b) An exception is thrown
c) {‘a’:‘b’:‘c’:}
d) {1: ‘a’, 2: ‘b’, 3: ‘c’}

32. What will be the output of the following Python code?


>>> a=dict()
>>> a[1]
a) An exception is thrown since the dictionary is empty
b) ‘‘
c) 1
d) 0

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Lambda is a function in python?


A. True
B. False
C. Lambda is a function in python but user can not use it.
D. None of the above

2. What is the output of the following program?


z = lambda x : x * x
print(z(6))
A. 6
B. 36
C. 0
D. Error

1.a2.b3.4.5.

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. To open a file c:\scores.txt for reading, we use _____________


a) infile = open(“c:\scores.txt”, “r”)
b) infile = open(“c:\\scores.txt”, “r”)
c) infile = open(file = “c:\scores.txt”, “r”)
d) infile = open(file = “c:\\scores.txt”, “r”)

2. To open a file c:\scores.txt for writing, we use ____________


a) outfile = open(“c:\scores.txt”, “w”)

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”)

3. To open a file c:\scores.txt for appending data, we use ____________


a) outfile = open(“c:\\scores.txt”, “a”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)

4. Which of the following statements are true?


a) When you open a file for reading, if the file does not exist, an error occurs
b) When you open a file for writing, if the file does not exist, a new file is created
c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file
d) All of the mentioned

5. To read two characters from a file object infile, we use ____________


a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()

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()

7. What will be the output of the following Python code?

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()

10. The readlines() method returns ____________


a) str
b) a list of lines
c) a list of single characters
d) a list of integers

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

12. What will be the output of the following Python code?

str = raw_input("Enter your input: ");

print "Received input is : ", str

a) Enter your input: Hello Python


Received input is : Hello Python
b) Enter your input: Hello Python
Received input is : Hello
c) Enter your input: Hello Python
Received input is : Python
d) None of the mentioned

13. What will be the output of the following Python code?

str = input("Enter your input: ");

print "Received input is : ", str

a) Enter your input: [x*5 for x in range(2,10,2)]


Received input is : [x*5 for x in range(2,10,2)]
b) Enter your input: [x*5 for x in range(2,10,2)]
Received input is : [10, 30, 20, 40]
c) Enter your input: [x*5 for x in range(2,10,2)]
Received input is : [10, 10, 30, 40]
d) None of the mentioned

14. Which one of the following is not attributes of file?

a) closed
b) softspace
c) rename
d) mode

15. What is the use of tell() method in python?

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

16. What is the current syntax of rename() a file?

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

17. What is the current syntax of remove() a file?


a) remove(file_name)
b) remove(new_file_name, current_file_name,)
c) remove(() , file_name))
d) none of the mentioned

18. What will be the output of the following Python code?

fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name

# Assuming file has following 5 lines

# This is 1st line

# This is 2nd line

# This is 3rd line

# This is 4th line

# This is 5th line

for index in range(5):


line = fo.next()
print "Line No %d - %s" % (index, line)

# Close opened file


fo.close()

a) Compilation Error
b) Syntax Error
c) Displays Output
d) None of the mentioned

19. What is the use of seek() method in files?


a) sets the file’s current position at the offset
b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned

20. What is the use of truncate() method in file?

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.

21. Which is/are the basic I/O connections in file?


a) Standard Input
b) Standard Output
c) Standard Errors
d) All of the mentioned

22. What will be the output of the following Python code?

import sys
sys.stdout.write(' Hello\n')
sys.stdout.write('Python\n')

a) Compilation Error
b) Runtime Error
c) Hello Python
d) Hello
Python

23. Which of the following mode will refer to binary data?


a) r
b) w
c) +
d) b

24. What is the pickling?


a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned

25. What is unpickling?


a) It is used for object serialization
b) It is used for object deserialization
c) None of the mentioned
d) All of the mentioned

26. What is the correct syntax of open() function?


a) file = open(file_name [, access_mode][, buffering])
b) file object = open(file_name [, access_mode][, buffering])
c) file object = open(file_name)
d) none of the mentioned.

27. What will be the output of the following Python code?

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

28. Correct syntax of file.writelines() is?


a) file.writelines(sequence)
b) fileObject.writelines()
c) fileObject.writelines(sequence)
d) none of the mentioned

29. Correct syntax of file.readlines() is?


a) fileObject.readlines( sizehint );
b) fileObject.readlines();
c) fileObject.readlines(sequence)
d) none of the mentioned.

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

31. What is the use of “w” in file handling?


a) Read
b) Write
c) Append
d) None of the mentioned

32. What is the use of “a” in file handling?


a) Read
b) Write
c) Append
d) None of the mentioned

33. Which function is used to read all the characters?


a) Read()
b) Readcharacters()
c) Readall()
d) Readchar()

34. Which function is used to read single line from file?


a) Readline()
b) Readlines()
c) Readstatement()
d) Readfullline()

35. Which function is used to write all the characters?


a) write()
b) writecharacters()
c) writeall()
d) writechar()

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()

37. Which function is used to close a file in python?


a) Close()
b) Stop()
c) End()
d) Closefile()

38. Is it possible to create a text file in python?


a) Yes
b) No
c) Machine dependent
d) All of the mentioned

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+

40. Which of the following is not a valid mode to open a file?


a) ab
b) rw
c) r+
d) w+

41. What is the difference between r+ and w+ modes?


a) no difference
b) in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
c) in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
d) depends on the operating system

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

44. How do you close a file object (fp)?


a) close(fp)
b) fclose(fp)

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

46. How do you rename a file?


a) fp.name = ‘new_name.txt’
b) os.rename(existing_name, new_name)
c) os.rename(fp, new_name)
d) os.set_name(existing_name, new_name)

47. How do you delete a file?


a) del(fp)
b) fp.delete()
c) os.remove(‘file’)
d) os.delete(‘file’)

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

49. What happens if no arguments are passed to the seek function?


a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. How many except statements can a try-except block have?


a) zero
b) one
c) more than one
d) more than zero

2. When will the else part of try-except-else be executed?


a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block

3. Is the following Python code valid?


try:
# Do somethingexcept:
# Do somethingfinally:
# Do something
a) no, there is no such thing as finally

77 | P a g e
b) no, finally cannot be used with except
c) no, finally must come before except
d) yes

4. Is the following Python code valid?


try:
# Do somethingexcept:
# Do somethingelse:
# Do something
a) no, there is no such thing as else
b) no, else cannot be used with except
c) no, else must come before except
d) yes

5. Can one block of except statements handle multiple exception?


a) yes, like except TypeError, SyntaxError [,…]
b) yes, like except [TypeError, SyntaxError]
c) no
d) none of the mentioned

6. When is the finally block executed?


a) when there is no exception
b) when there is an exception
c) only if some condition that has been specified is satisfied
d) always

7. What will be the output of the following Python code?


def foo():
try:
return 1
finally:
return 2
k = foo()print(k)
a) 1
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block

8. What will be the output of the following Python code?


def foo():
try:
print(1)
finally:
print(2)
foo()
a) 1 2
b) 1
c) 2
d) none of the mentioned

9. What happens when ‘1’ == 1 is executed?


a) we get a True
b) we get a False

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

11. What will be the output of the following Python code?


x=10
y=8assert x>y, 'X too small'
a) Assertion Error
b) 10 8
c) No output
d) 108

12. What will be the output of the following Python code?


#generatordef f(x):
yield x+1
g=f(8)print(next(g))
a) 8
b) 9
c) 7
d) Error

13. What will be the output of the following Python code?


def a():
try:
f(x, 4)
finally:
print('after f')
print('after f?')
a()
a) No output
b) after f?
c) error
d) after f

14. What will be the output of the following Python code?


def f(x):
for i in range(5):
yield i
g=f(8)print(list(g))
a) [0, 1, 2, 3, 4]
b) [1, 2, 3, 4, 5, 6, 7, 8]
c) [1, 2, 3, 4, 5]
d) [0, 1, 2, 3, 4, 5, 6, 7]
Explanation: The output of the code shown above is a list containing whole numbers in the range (5).
Hence the output of this code is: [0, 1, 2, 3, 4].

15. The error displayed in the following Python code is?


import itertools
l1=(1, 2, 3)

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

16. Which of the following is not an exception handling keyword in Python?


a) try
b) except
c) accept
d) finally

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

18. What will be the output of the following Python code?


lst = [1, 2, 3]
lst[3]
a) NameError
b) ValueError
c) IndexError
d) TypeError
19. What will be the output of the following Python code?
t[5]
a) IndexError
b) NameError
c) TypeError
d) ValeError

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

21. What will be the output of the following Python code?


int('65.43')
a) ImportError
b) ValueError
c) TypeError
d) NameError

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)

23. Identify the type of error in the following Python codes?


Print(“Good Morning”)print(“Good night)
a) Syntax, Syntax
b) Semantic, Syntax
c) Semantic, Semantic
d) Syntax, Semantic

24. Which of the following statements is true?


a) The standard exceptions are automatically imported into Python programs
b) All raised standard exceptions must be handled in Python
c) When there is a deviation from the rules of a programming language, a semantic error is thrown
d) If any exception is thrown in try block, else block is executed

25. Which of the following is not a standard exception in Python?


a) NameError
b) IOError
c) AssignmentError
d) ValueError

26. Syntax errors are also known as parsing errors.


a) True
b) False

27. An exception is ____________


a) an object
b) a special function
c) a standard module
d) a module

28. _______________________ exceptions are raised as a result of an error in opening a


particular file.
a) ValueError
b) TypeError
c) ImportError
d) IOError

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which of these definitions correctly describes a module?


a) Denoted by triple quotes for providing the specification of certain program elements
b) Design and implementation of specific functionality to be incorporated into a program
c) Defines the specification of how it is to be used
d) Any program that reuses code

2. Which of the following is not an advantage of using modules?


a) Provides a means of reuse of program code
b) Provides a means of dividing up tasks
c) Provides a means of reducing the size of the program
d) Provides a means of testing individual parts of the program

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

5. Which of the following is true about top-down design process?


a) The details of a program design are addressed before the overall design
b) Only the details of the program are addressed
c) The overall design of the program is addressed before the details
d) Only the design of the program is addressed

6. In top-down design every module is broken into same number of submodules.


a) True
b) False

7. All modular designs are because of a top-down design process.


a) True
b) False

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

11. Which of the following is false about “from-import” form of import?


a) The syntax is: from modulename import identifier
b) This form of import prevents name clash
c) The namespace of imported module becomes part of importing module
d) The identifiers in module are accessed directly as: identifier

12. Which of the statements about modules is false?


a) In the “from-import” form of import, identifiers beginning with two underscores are private and
aren’t imported
b) dir() built-in function monitors the items in the namespace of the main module
c) In the “from-import” form of import, all identifiers regardless of whether they are private or public
are imported
d) When a module is loaded, a compiled version of the module with file extension .pyc is
automatically produced

13. What will be the output of the following Python code?


from math import factorialprint(math.factorial(5))
a) 120
b) Nothing is printed
c) Error, method factorial doesn’t exist in math module
d) Error, the statement should be: print(factorial(5))

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

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

2. _____ is used to create an object.


a) class
b) constructor
c) User-defined functions
d) In-built functions

3. What will be the output of the following Python code?


class test:
def __init__(self,a="Hello World"):
self.a=a

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

4. What is setattr() used for?


a) To access the attribute of the object
b) To set an attribute
c) To check if an attribute exists or not
d) To delete an attribute

5. What is getattr() used for?


a) To access the attribute of the object
b) To delete an attribute
c) To check if an attribute exists or not
d) To set an attribute

6. What will be the output of the following Python code?


class change:
def __init__(self, x, y, z):
self.a = x + y + z

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

7. What will be the output of the following Python code?


class test:
def __init__(self,a):
self.a=a

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

8. Is the following Python code correct?


>>> class A:
def __init__(self,b):
self.b=b
def display(self):
print(self.b)>>> obj=A("Hello")>>> del obj
a) True
b) False

9. What will be the output of the following Python code?


class test:
def __init__(self):
self.variable = 'Old'
self.Change(self.variable)
def Change(self, var):
var = 'New'
obj=test()print(obj.variable)
a) Error because function change can’t be called in the __init__ function
b) ‘New’ is printed
c) ‘Old’ is printed
d) Nothing is printed

10. What is Instantiation in terms of OOP terminology?


a) Deleting an instance of class
b) Modifying an instance of class
c) Copying an instance of class
d) Creating an instance of class

11. What will be the output of the following Python code?


class fruits:
def __init__(self, price):
self.price = price
obj=fruits(50)

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

13. Which of the following is not a class method?


a) Non-static
b) Static
c) Bounded
d) Unbounded

14. Which of the following Python code creates an empty class?


a)
class A:
return
b)
class A:
pass
c)
class A:
d) It is not possible to create an empty class

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

16. Special methods need to be explicitly called during object creation.


a) True
b) False

17. Is the following Python code valid?


class B(object):
def first(self):
print("First method called")
def second():
print("Second method called")
ob = B()
B.first(ob)
a) It isn’t as the object declaration isn’t right
b) It isn’t as there isn’t any __init__ method for initializing class members
c) Yes, this method of calling is called unbounded method call

86 | P a g e
d) Yes, this method of calling is called bounded method call

18. What is hasattr(obj,name) used for?


a) To access the attribute of the object
b) To delete an attribute
c) To check if an attribute exists or not
d) To set an attribute
19. What is delattr(obj,name) used for?
a) To print deleted attribute
b) To delete an attribute
c) To check if an attribute is deleted or not
d) To set an attribute

20. __del__ method is used to destroy instances of a class.


a) True
b) False

21. What does print(Test.__name__) display (assuming Test is the name of the class)?
a) ()
b) Exception is thrown
c) Test
d) __main__

22. What will be the output of the following Python code?


class stud:
def __init__(self, roll_no, grade):
self.roll_no = roll_no
self.grade = grade
def display (self):
print("Roll no : ", self.roll_no, ", Grade: ", self.grade)
stud1 = stud(34, ‘S’)
stud1.age=7print(hasattr(stud1, 'age'))
a) Error as age isn’t defined
b) True
c) False
d) 7

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which of the following best describes inheritance?


a) Ability of a class to derive members of another class as a part of its own definition
b) Means of bundling instance variables and methods in order to restrict access to certain class
members
c) Focuses on variables and passing of variables to functions

87 | P a g e
d) Allows for implementation of elegant software that is well designed and easily modified

2. Which of the following statements is wrong about inheritance?


a) Protected members of a class can be inherited
b) The inheriting class is called a subclass
c) Private members of a class can be inherited and accessed
d) Inheritance is one of the features of OOP

3. What will be the output of the following Python code?


class Demo:
def __new__(self):
self.__init__(self)
print("Demo's __new__() invoked")
def __init__(self):
print("Demo's __init__() invoked")class Derived_Demo(Demo):
def __new__(self):
print("Derived_Demo's __new__() invoked")
def __init__(self):
print("Derived_Demo's __init__() invoked")def main():
obj1 = Derived_Demo()
obj2 = Demo()
main()
a) Derived_Demo’s __init__() invoked
Derived_Demo's __new__() invoked
Demo's __init__() invoked
Demo's __new__() invoked
b) Derived_Demo's __new__() invoked
Demo's __init__() invoked
Demo's __new__() invoked
c) Derived_Demo's __new__() invoked
Demo's __new__() invoked
d) Derived_Demo’s __init__() invoked
Demo's __init__() invoked

4. What will be the output of the following Python code?


class Test:
def __init__(self):
self.x = 0class Derived_Test(Test):
def __init__(self):
self.y = 1def main():
b = Derived_Test()
print(b.x,b.y)
main()
a) 0 1
b) 0 0
c) Error because class B inherits A but variable x isn’t inherited
d) Error because when object is created, argument must be passed like Derived_Test(1)

5. What will be the output of the following Python code?


class A():
def disp(self):
print("A disp()")class B(A):

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()

6. All subclasses are a subtype in object-oriented programming.


a) True
b) False

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)

9. What will be the output of the following Python code?


class Test:
def __init__(self):
self.x = 0class Derived_Test(Test):
def __init__(self):
Test.__init__(self)
self.y = 1def main():
b = Derived_Test()
print(b.x,b.y)
main()
a) Error because class B inherits A but variable x isn’t inherited
b) 0 0
c) 0 1
d) Error, the syntax of the invoking method is wrong

10. What will be the output of the following Python code?


class A:
def __init__(self, x= 1):
self.x = xclass der(A):
def __init__(self,y = 2):
super().__init__()
self.y = ydef main():
obj = der()
print(obj.x, obj.y)
main()
a) Error, the syntax of the invoking method is wrong
b) The program runs fine but nothing is printed
c) 1 0
d) 1 2

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

12. Which of the following is not a type of inheritance?


a) Double-level
b) Multi-level
c) Single-level
d) Multiple

13. What does built-in function help do in context of classes?


a) Determines the object name of any value
b) Determines the class identifiers of any value
c) Determines class description of any built-in type
d) Determines class description of any user-defined built-in type

14. What will be the output of the following Python code?


class A:
def one(self):
return self.two()

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

15. What type of inheritance is illustrated in the following Python code?


class A():
passclass B():
passclass C(A,B):
pass
a) Multi-level inheritance
b) Multiple inheritance
c) Hierarchical inheritance
d) Single-level inheritance

16. What type of inheritance is illustrated in the following Python code?


class A():
passclass B(A):
passclass C(B):
pass
a) Multi-level inheritance
b) Multiple inheritance

90 | P a g e
c) Hierarchical inheritance
d) Single-level inheritance

17. What does single-level inheritance mean?


a) A subclass derives from a class which in turn derives from another class
b) A single superclass inherits from multiple subclasses
c) A single subclass derives from a single superclass
d) Multiple base classes inherit a single derived class

18. What will be the output of the following Python code?


class A:
def __init__(self):
self.__i = 1
self.j = 5

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

19. Which of the following statements isn’t true?


a) A non-private method in a superclass can be overridden
b) A derived class is a subset of superclass
c) The value of a private variable in the superclass can be changed in the subclass
d) When invoking the constructor from a subclass, the constructor of superclass is automatically
invoked

20. What will be the output of the following Python code?


>>> class A:
pass>>> class B(A):
pass>>> obj=B()>>> isinstance(obj,A)
a) True
b) False
c) Wrong syntax for isinstance() method
d) Invalid method for classes

21. Which of the following statements is true?


a) The __new__() method automatically invokes the __init__ method
b) The __init__ method is defined in the object class
c) The __eq(other) method is defined in the object class
d) The __repr__() method is defined in the object class

22. Method issubclass() checks if a class is a subclass of another class.


a) True
b) False

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

24. What will be the output of the following Python code?


class A:
def __init__(self):
self._x = 5 class B(A):
def display(self):
print(self._x)def main():
obj = B()
obj.display()
main()
a) Error, invalid syntax for object declaration
b) Nothing is printed
c) 5
d) Error, private class member can’t be accessed in a subclass

25. What will be the output of the following Python code?


class A:
def __init__(self,x=3):
self._x = x class B(A):
def __init__(self):
super().__init__(5)
def display(self):
print(self._x)def main():
obj = B()
obj.display()

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()

27. What will be the output of the following Python code?


class A:
def test(self):
print("test of A called")class B(A):
def test(self):
print("test of B called")
super().test() class C(A):
def test(self):
print("test of C called")
super().test()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
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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Which is the most appropriate definition for recursion?


a) A function that calls itself
b) A function execution instance that calls another execution instance of the same function
c) A class method that calls another class method
d) An in-built method that is automatically called

2. Only problems that are recursively defined can be solved using recursion.

94 | P a g e
a)True
b) False

3. Which of these is false about recursion?


a) Recursive function can be replaced by a non-recursive function
b) Recursive functions usually take more memory space than non-recursive function
c) Recursive functions run faster than non-recursive function
d) Recursion makes programs easier to understand

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)

5. What will be the output of the following Python code?


def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))

a) 13
b) 7
c) Infinite loop
d) 17

6. What is tail recursion?


a) A recursive function that has two base cases
b) A function where the recursive functions leads to an infinite loop
c) A recursive function where the function doesn’t return anything and just prints the values
d) A function where the recursive call is the last thing executed by the function

7. Which of the following statements is false about recursion?


a) Every recursive function must have a base case
b) Infinite recursion can occur if the base case isn’t properly mentioned
c) A recursive function makes the code easier to understand
d) Every recursive function must have a return value

8. What will be the output of the following Python code?


def fun(n):
if (n > 100):
return n - 5
return fun(fun(n+11));
print(fun(45))

a) 50

95 | P a g e
b) 100
c) 74
d) Infinite loop

9. Recursion and iteration are the same programming approach.


a)True
b) False

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

11. Which of these is not true about recursion?


a) Making the code look clean
b) A complex task can be broken into sub-problems
c) Recursive calls take up less memory
d) Sequence generation is easier than a nested iteration

12. Which of these is not true about recursion?


a) It’s easier to code some real-world problems using recursion than non-recursive equivalent
b) Recursive functions are easy to debug
c) Recursive calls take up a lot of memory
d) Programs using recursion take longer time than their non-recursive equivalent

13. What will be the output of the following Python code?


def a(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return a(n-1)+a(n-2)
for i in range(0,4):
print(a(i),end=" ")

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

16. Which of the following option is wrong?


a) Fibonacci number can be calculated by using Dynamic programming
b) Fibonacci number can be calculated by using Recursion method
c) Fibonacci number can be calculated by using Iteration method
d) No method is defined to calculate Fibonacci number.

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

21. What is the objective of tower of hanoi puzzle?


a) To move all disks to some other rod by following rules
b) To divide the disks equally among the three rods by following rules
c) To move all disks to some other rod in random order
d) To divide the disks equally among three rods in random order

22. Which of the following is NOT a rule of tower of hanoi puzzle?


a) No disk should be placed over a smaller disk
b) Disk can only be moved if it is the uppermost disk of the stack
c) No disk should be placed over a larger disk
d) Only one disk can be moved at a time

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

26. Space complexity of recursive solution of tower of hanoi puzzle is ________


a) O(1)
b) O(n)
c) O(log n)

98 | P a g e
d) O(n log n)

27. Recursive solution of tower of hanoi problem is an example of which of the


following algorithm?
a) Dynamic programming
b) Backtracking
c) Greedy algorithm
d) Divide and conquer

28. Tower of hanoi problem can be solved iteratively.


a) True
b) False

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1. Where is linear searching used?


a) When the list has only a few elements
b) When performing a single search in an unordered list
c) Used all the time
d) When the list has only a few elements and When performing a single search in an unordered list.

2. What is the best case for linear search?


a) O(nlogn)
b) O(logn)
c) O(n)

99 | P a g e
d) O(1)

3. What is the worst case for linear search?


a) O(nlogn)
b) O(logn)
c) O(n)
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)

5. Which of the following is a disadvantage of linear search?


a) Requires more space
b) Greater time complexities compared to other searching algorithms
c) Not easy to understand
d) Not easy to implement
6. Is there any difference in the speed of execution between linear serach(recursive)
vs linear search(lterative)?
a) Both execute at same speed
b) Linear search(recursive) is faster
c) Linear search(Iterative) is faster
d) Cant be said

7. Is the space consumed by the linear search(recursive) and linear search(iterative)


same?
a) No, recursive algorithm consumes more space
b) No, recursive algorithm consumes less space
c) Yes
d) Nothing can be said

8. What is the worst case runtime of linear search(recursive) algorithm?


a) O(n)
b) O(logn)
c) O(n2)
d) O(nx)

9. Linear search(recursive) algorithm used in _____________


a) When the size of the dataset is low
b) When the size of the dataset is large
c) When the dataset is unordered
d) Never used

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

12. What is the best case runtime of linear search(recursive) algorithm on an


ordered set of elements?
a) O(1)
b) O(n)
c) O(logn)
d) O(nx)

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

15. What is the advantage of recursive approach than an iterative approach?


a) Consumes less memory
b) Less code and easy to implement
c) Consumes more memory
d) More code has to be written

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)

20. Which of the following is not an application of binary search?


a) To find the lower/upper bound in an ordered sequence
b) Union of intervals
c) Debugging
d) To search in unordered list.

21. Binary Search can be categorized into which of the following?


a) Brute Force technique
b) Divide and conquer
c) Greedy algorithm
d) Dynamic programming

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

24. What is the time complexity of binary search with iteration?

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

 MULTIPLE CHOICE QUESTIONS ANSWERS

1.What is an in-place sorting algorithm?


a) It needs O(1) or O(logn) memory to create auxiliary locations
b) The input is already sorted and in-place
c) It requires additional storage
d) It requires additional space

2. In the following scenarios, when will you use selection sort?


a) The input is already sorted
b) A large file has to be sorted
c) Large values need to be sorted with small keys
d) Small values need to be sorted with large keys

3. What is the worst case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

4. What is the advantage of selection sort over other sorting techniques?


a) It requires no additional storage space
b) It is scalable
c) It works best for inputs which are already sorted
d) It is faster than any other sorting technique

5. What is the average case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

6. What is the disadvantage of selection sort?


a) It requires auxiliary memory
b) It is not scalable

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

9. What is the best case complexity of selection sort?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)

10. Merge sort uses which of the following technique to implement sorting?
a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming

11. What is the average case time complexity of merge sort?


a) O(n log n)
b) O(n2)
c) O(n2 聽 log n)
d) O(n log n2)
12. What is the auxiliary space complexity of merge sort?
a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)

13. Merge sort can be implemented using O(1) auxiliary space.


a) true
b) false

14. What is the worst case time complexity of merge sort?


a) O(n log n)

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)

17. Which of the following is not a variant of merge sort?


a) in-place merge sort
b) bottom up merge sort
c) top down merge sort
d) linear merge sort

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

19. Which of the following is not in place sorting algorithm?


a) merge sort
b) quick sort
c) heap sort
d) insertion sort

20. Which of the following is not a stable sorting algorithm?


a) Quick sort
b) Cocktail sort
c) Bubble sort
d) Merge sort

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

Take Python Quiz To test your Knowledge


Below are few Python MCQ test that checks your basic knowledge of Python. This Python Test contains
around 20 questions of multiple choice with 4 options. You have to select the right answer to a question. You
can see the correct answer by clicking view answer link.

Also, Read Best Python Flask interview questions.

Q1. Which of the following is the use of id() function in python?

A. Every object doesn’t have a unique id


B. Id returns the identity of the object
C. All of the mentioned
D. None of the mentioned

Q2. Is Python case sensitive when dealing with identifiers?

A. yes
B. no

Q3. All keywords in Python are in

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

Q6. What is the return type of function id?

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. Hello ‘foo’ and foo


B. Hello foo and foo
C. Hello foo and ‘bin’
D. Error

Q8. Which of the following data types is not supported in python ?

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

Q10. Select the reserved keyword in python-


A. else
B. raise
C. import
D. All of the above

Q11. Are nested if-else are allowed in Python?

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

Q14. The format function, when applied on a string returns :

A. list
B. bool
C. int
D. str

Q15. Which statement is correct....??

A. List is mutable & Tuple is immutable


B. List is immutable & Tuple is mutable
C. Both are Mutable.
D. Both are Immutable

Q16. What is the maximum possible length of an identifier?

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

Q18. What will be the output of 7^10 in python?

A. 13
B. 15
C. 2
D. None of these

Q19. 19 % 2 in python

A. 2
B. 17
D. None of these

Q20. Which of the following has more precedance?

A. /
B. +
C. ()
D. -
Q21. Is Tuple mutable?

A. yes
B. no

Please Visit OnlineInterviewquestions.com to download more pdfs


Question Bank
* MCQ Questions
1. Is Python case sensitive when dealing with identifiers?
a) yes
b) no
c) machine dependent
d) none of the mentioned
Answer: a
Explanation: Case is always significant.

2. What is the maximum possible length of an identifier?


a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned
Answer: d
Explanation: Identifiers can be of any length.

3. Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned
Answer: d
Explanation: All the statements will execute successfully but at the cost of reduced
readability.

4. Which of the following is an invalid variable?


a) my_string_1
b) 1st_string
c) foo
d) _
Answer: b
Explanation: Variable names should not start with a number.

5. 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
Answer: a
Explanation: As Python has no concept of private variables, leading underscores are
used to indicate variables that must not be accessed from outside the class.

6. Which of the following is not a keyword?


a) eval
b) assert
c) nonlocal
d) pass
Answer: a
Explanation: eval can be used as a variable.

7. All keywords in Python are in _________


a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned
Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.

8. Which of the following is true for variable names in Python?


a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special characters allowed
d) none of the mentioned
Answer: a
Explanation: Variable names can be of any length.

9. Which of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
Answer: b
Explanation: Spaces are not allowed in variable names.

10. Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on
Answer: b
Explanation: in is a keyword.

11. What is the output of print 0.1 + 0.2 == 0.3?


a) True
b) False
c) Machine dependent
d) Error
View Answer
Answer: b
Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The
round off errors from 0.1 and 0.2 accumulate and hence there is a difference of
5.5511e-17 between (0.1 + 0.2) and 0.3.

12. 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
Explanation: l (or L) stands for long.

13. What is the type of inf?


a) Boolean
b) Integer
c) Float
d) Complex
Answer: c
Explanation: Infinity is a special case of floating point numbers. It can be obtained by
float(‘inf’).

14. What does ~4 evaluate to?


a) -5
b) -4
c) -3
d) +3
Answer: a
Explanation: ~x is equivalent to -(x+1).

15.What does ~~~~~~5 evaluate to?


a) +5
b) -11
c) +11
d) -5
Answer: a
Explanation: ~x is equivalent to -(x+1).

16.Which of the following is incorrect?


a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964
Answer: d
Explanation: Numbers starting with a 0 are octal numbers but 9 isn’t allowed in octal
numbers.
17. What is the result of cmp(3, 1)?
a) 1
b) 0
c) True
d) False
Answer: a
Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y.

18. Which of the following is incorrect?


a) float(‘inf’)
b) float(‘nan’)
c) float(’56’+’78’)
d) float(’12+34′)
Answer: d
Explanation: ‘+’ cannot be converted to a float.
19. What is the result of round(0.5) – round(-0.5)?
a) 1.0
b) 2.0
c) 0.0
d) None of the mentioned
Answer: b
Explanation: Python rounds off numbers away from 0 when the number to be
rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1.

20. What does 3 ^ 4 evaluate to?


a) 81
b) 12
c) 0.75
d) 7
Answer: d
Explanation: ^ is the Binary XOR operator.

21. Which of the following statements create a dictionary?


a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned
Answer: d
Explanation: Dictionaries are created by specifying keys and values.
22. What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
a) “john”, 40, 45, and “peter”
b) “john” and “peter”
c) 40 and 45
d) d = (40:”john”, 45:”peter”)
Answer: b
Explanation: Dictionaries appear in the form of keys and values.

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.

27. Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
Answer: b
Explanation: Values cannot be modified in the case of tuple, that is, tuple is
immutable.

28. What will be the output of the following Python code?


>>>t=(1,2,4,3)
>>>t[1:3]

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.

29. What will be the output of the following Python code?


>>>t=(1,2,4,3)
>>>t[1:-1]

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.

30. What will be the output of the following Python code?


>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]

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.

31. What will be the output of the following Python code?


d = {"john":40, "peter":45}
d["john"]

a) 40
b) 45
c) “john”
d) “peter”
Answer: a
Explanation: Execute in the shell to verify.

32. What will be the output of the following Python code?


>>>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]
Answer: a
Explanation: * operator concatenates tuple.

33. Which of these about a set is not true?


a) Mutable data type
b) Allows duplicate values
c) Data type with unordered values
d) Immutable data type
Answer: d
Explanation: A set is a mutable data type with non-duplicate, unordered values,
providing the usual mathematical set operations.

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.

35. What will be the output of the following Python code?


nums = set([1,1,2,3,3,3,4,4])print(len(nums))
a) 7
b) Error, invalid syntax for formation of set
c) 4
d) 8
Answer: c
Explanation: A set doesn’t have duplicate items.

36. What will be the output of the following Python code?


a = [5,5,6,7,7,7]
b = set(a)def test(lst):
if lst in b:
return 1
else:
return 0for i in filter(test, a):
print(i,end=" ")
a) 5 5 6
b) 5 6 7
c) 5 5 6 7 7 7
d) 5 6 7 7 7

37. Which of the following statements is used to create an empty set?


a) { }
b) set()
c) [ ]
d) ( )
Answer: b
Explanation: { } creates a dictionary not a set. Only set() creates an empty set.

38. What will be the output of the following Python code?


>>> a={5,4}>>> b={1,2,4,5}>>> a<b
a) {1,2}
b) True
c) False
d) Invalid operation
Answer: b
Explanation: a<b returns True if a is a proper subset of b.

39. If a={5,6,7,8}, which of the following statements is false?


a) print(len(a))
b) print(min(a))
c) a.remove(5)
d) a[2]=45
Answer: d
Explanation: The members of a set can be accessed by their index values since the
elements of the set are unordered.

40. If a={5,6,7}, what happens when a.add(5) is executed?


a) a={5,5,6,7}
b) a={5,6,7}
c) Error as there is no add function for set data type
d) Error as 5 already exists in the set
Answer: b
Explanation: There exists add method for set data type. However 5 isn’t added again
as set consists of only non-duplicate elements and 5 already exists in the set. Execute
in python shell to verify.

41. What will be the output of the following Python code?


>>> a={4,5,6}>>> b={2,8,6}>>> a+b
a) {4,5,6,2,8}
b) {4,5,6,2,8,6}
c) Error as unsupported operand type for sets
d) Error as the duplicate item 6 is present in both sets
Answer: c
Explanation: Execute in python shell to verify.

*Answer In One Sentence :

1. What is name space in Python?


2. What are local variables and global variables in Python?
3. Is python case sensitive?
4. What is type conversion in Python?
5. Is indentation required in python?
6. What is the difference between Python Arrays and lists?
7. What is a lambda function?
8. What is self in Python?
9. How does break, continue and pass work?
10. How can you randomize the items of a list in place in Python?
11. What are python iterators?
12. How do you write comments in python?
13. What is pickling and unpickling?
14. How will you convert a string to all lowercase?
15. How will you capitalize the first letter of string?
16. How to comment multiple lines in python?
17. What are docstrings in Python?
18. What is the purpose of is, not and in operators?
19. What is a dictionary in Python?
20. What does len() do?
21. Explain split(), sub(), subn() methods of “re” module in Python.
22. What are Python packages?
23. Does Python have OOps concepts?
24. How to import modules in python?
25. How are classes created in Python?
26. What is Polymorphism in Python?
27. Define encapsulation in Python?
28. How do you do data abstraction in Python?
29. Does python make use of access specifiers?
30. How to create an empty class in Python?

* Short Notes Questions :

1. Mention five benefits of using Python?


2. Explain what is Flask & its benefits?
3. Explain the key features of Python?
4. What are the global and local variables in Python?
5. Define modules in Python?
6. Define pickling and unpickling in Python?
7. Write a program to display Fibonacci sequence in Python?
8. Write a program to check whether the given number is prime or not?
9. What is the difference between range and xrange?
10. Does multiple inheritance is supported in Python?
11. Does Python make use of access specifiers?
12. Define Constructor in Python?
13. How can we create a constructor in Python programming?
14. How Does Python Handle Memory Management?
15. What Are The Optional Statements Possible Inside A Try-Except Block
In Python?
16. What Is Slicing In Python?
17. What Is %S In Python?
18. What Is The Index In Python?
19. Is A String Immutable Or Mutable In Python?
20. How Many Basic Types Of Functions Are Available In Python?

* Short Answer Questions :

1. How Do We Write A Function In Python?


2. What Is “Call By Value” In Python?
3. What Is “Call By Reference” In Python?
4. Is It Mandatory For A Python Function To Return A Value?Comment?
5. What Does The *Args Do In Python?
6. What Does The **Kwargs Do In Python?
7. Does Python Have A Main() Method?
8. What Is The Purpose Of “End” In Python?
9. When Should You Use The “Break” In Python?
10. What Is The Difference Between Pass And Continue In Python?
11. What Does The Ord() Function Do In Python?
12. What Is Rstrip() In Python?
13. How Is Python Thread Safe?
14. How Does Python Manage The Memory?
15. What Is A Tuple In Python?
16. Is Python List A Linked List?
17. What Is Class In Python?
18. What Are Attributes And Methods In A Python Class?
19. How To Assign Values For The Class Attributes At Runtime?
20. What Is Inheritance In Python Programming?

* Long Answer Questions :

1. What is the difference between lists and tuples?


2. Explain Inheritance in Python with an example.
3. What is a dictionary in Python?
4. What are negative indexes and why are they used?
5. What are split(), sub(), and subn() methods in Python?
6. How are range and xrange different from one another?
7. Explain all file processing modes supported in Python.
8. How are Python arrays and Python lists different from each other?
9. Explain List and Queues with example?
10. Explain All OOPS Concept With example?
Python MCQ (Multi Choice Questions)
Q. What is the maximum possible length of an identifier?
a. 16
b. 32
c. 64
d. None of these above

Answer: (d) None of these above


Explanation: The maximum possible length of an identifier is not defined in the python language. It
can be of any number.

Q. Who developed the Python language?


a. Zim Den
b. Guido van Rossum
c. Niene Stom
d. Wick van Rossum

Answer: (b) Guido van Rossum


Explanation: Python language was developed by Guido van Rossum in the Netherlands.

Q. In which year was the Python language developed?


a. 1995
b. 1972
c. 1981
d. 1989

Answer: (d) 1989


Explanation: Python language was developed by Guido van Rossum in 1989.

Q. In which language is Python written?


a. English
b. PHP
c. C
d. All of the above

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: (a) .py


Explanation: ".py" is the correct extension of the Python file.

Q. In which year was the Python 3.0 version developed?


a. 2008
b. 2000
c. 2010
d. 2005

Answer: (a) 2008


Explanation: Python 3.0 version was developed on December 3, 2008.
Q. What do we use to define a block of code in Python language?
a. Key
b. Brackets
c. Indentation
d. None of these

Answer: (c) Indentation


Explanation: Python uses indentation to define blocks of code. Indentations are simply spaces or tabs
used as an indicator that is part of the indent code child. As used in curly braces C, C++, and Java.

Q. Which character is used in Python to make a single line comment?


a. /
b. //
c. #
d. !

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. Which of the following statements is correct in this python code?


1. class Name:
2. def __init__(javatpoint):
3. javajavatpoint = java
4. name1=Name("ABC")
5. name2=name1
a. It will throw the error as multiple references to the same object is not possible
b. id(name1) and id(name2) will have same value
c. Both name1 and name2 will have reference to two different objects of class Name
d. All of the above

Answer: (b) id(name1) and id(name2) will have same value


Explanation: "name1" and "name2" refer to the same object, so id(name1) and id(name2) will have
the same value.

Q. What is the method inside the class in python language?


a. Object
b. Function
c. Attribute
d. Argument

Answer: (b) Function


Explanation: Function is also known as the method.
Q. Which of the following declarations is incorrect?
a. _x = 2
b. __x = 3
c. __xyz__ = 5
d. None of these

Answer: (d) None of these


Explanation: All declarations will execute successfully but at the expense of low readability.

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

Answer: (c) It indicates a private variable of a class


Explanation: Since there is no concept of private variables in Python language, the major underscore
is used to denote variables that cannot be accessed from outside the class.

Q. Which of the following is not a keyword in Python language?


a. val
b. raise
c. try
d. with

Answer: (a) val


Explanation: "val" is not a keyword in python language.

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

Answer: (b) Unlimited length


Explanation: None

Q. Which of the following declarations is incorrect in python language?


a. xyzp = 5,000,000
b. x y z p = 5000 6000 7000 8000
c. x,y,z,p = 5000, 6000, 7000, 8000
d. x_y_z_p = 5,000,000

Answer: (b) x y z p = 5000 6000 7000 8000


Explanation: Spaces are not allowed in variable names.

Q. Which of the following words cannot be a variable in python language?


a. _val
b. val
c. try
d. _try_

Answer: (c) try


Explanation: "try" is a keyword.
Q. Which of the following operators is the correct option for power(ab)?
a. a^b
b. a**b
c. a ^ ^ b
d. a ^ * b

Answer: (b) a**b


Explanation: The power operator in python is a**b, i.e., 2**3=8.

Q. Which of the following precedence order is correct in Python?


a. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
b. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential
c. Division, Multiplication, Addition, Subtraction, Parentheses, Exponential
d. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

Answer: (a) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction


Explanation: PEMDAS (similar to BODMAS).

Q. Which one of the following has the same precedence level?


a. Division, Power, Multiplication, Addition and Subtraction
b. Division and Multiplication
c. Subtraction and Division
d. Power and Division

Answer: (b) Division and Multiplication


Explanation: None

Q. Which one of the following has the highest precedence in the expression?
a. Division
b. Subtraction
c. Power
d. Parentheses

Answer: (d) Parentheses


Explanation: PEMDAS (similar to BODMAS).

Q. Which of the following functions is a built-in function in python language?


a. val()
b. print()
c. print()
d. None of these

Answer: (b) print()


Explanation: The print() function is a built-in function in python language that prints a value directly
to the system.

Q. Study the following function:


round(4.576)
What will be the output of this function?
a. 4
b. 5
c. 576
d. 5

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 of the following is correctly evaluated for this function?


pow(x,y,z)
a. (x**y) / z
b. (x / y) * z
c. (x**y) % z
d. (x / y) / z

Answer: (c) (x**y) % z


Explanation: None

Q. Study the following function:


all([2,4,0,6])
What will be the output of this function?
a. False
b. True
c. 0
d. Invalid code

Answer: (a) False


Explanation: If any element is zero, it returns a false value, and if all elements are non-zero, it returns
a true value. Hence, the output of this "all([2,4,0,6])" function will be false.

Q. Study the following program:


x=1
while True:
if x % 5 = = 0:
break
print(x)
x+=1
What will be the output of this code?
a. error
b. 2 1
c. 0 3 1
d. None of these

Answer: (a) error


Explanation: Syntax error, there should not be a space between + and =.

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) Infile = open(''c:\\scores.txt'', ''r'')


Explanation: None

Q. Study the following code:


x = ['XX', 'YY']
for i in a:
i.lower()
print(a)
What will be the output of this program?
a. ['XX', 'YY']
b. ['xx', 'yy']
c. [XX, yy]
d. None of these

Answer: (a) ['XX', 'YY']


Explanation: None

Q. Study the following function:


import math
abs(math.sqrt(36))
What will be the output of this code?
a. Error
b. -6
c. 6
d. 6.0

Answer: (d) 6.0


Explanation: This function prints the square of the value.

Q. Study the following function:


any([5>8, 6>3, 3>1])
What will be the output of this code?
a. False
b. Ture
c. Invalid code
d. None of these

Answer: (b) True


Explanation: None

Q. Study the following statement:


>>>"a"+"bc"
What will be the output of this statement?
a. a+bc
b. abc
c. a bc
d. a

Answer: (b) abc


Explanation: In Python, the "+" operator acts as a concatenation operator between two strings.

Q. Study the following code:


>>>"javatpoint"[5:]
What will be the output of this code?
a. javatpoint
b. java
c. point
d. None of these

Answer: (c) point


Explanation: Slice operation is performed on the string.
Q. The output to execute string.ascii_letters can also be obtained from:?
a. character
b. ascii_lowercase_string.digits
c. lowercase_string.upercase
d. ascii_lowercase+string.ascii_upercase

Answer: (d) string.ascii_lowercase+string.ascii_upercase


Explanation: None

Q. Study the following statements:


1. >>> str1 = "javat"
2. >>> str2 = ":"
3. >>> str3 = "point"
4. >>> str1[-1:]
What will be the output of this statement?
a. t
b. j
c. point
d. java

Answer: (a) t
Explanation: The correct output of this program is "t" because -1 corresponds to the last index.

Q. Study the following code:


>>> print (r"\njavat\npoint")
What will be the output of this statement?
a. java
point
b. java point
c. \njavat\npoint
d. Print the letter r and then javat and then point

Answer: (c) \njavat\npoint


Explanation: None

Q. Study the following statements:


>>> print(0xA + 0xB + 0xC)
What will be the output of this statement?
a. 33
b. 63
c. 0xA + 0xB + 0xC
d. None of these

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.

Q. Study the following program:


1. class book:
2. def __init__(a, b):
3. a.o1 = b
4. class child(book):
5. def __init__(a, b):
6. a.o2 = b
7. obj = page(32)
8. print "%d %d" % (obj.o1, obj.o2)
Which of the following is the correct output of this program?
a. 32
b. 32 32
c. 32 None
d. Error is generated

Answer: (d) Error is generated


Explanation: Error is generated because self.o1 was never created.

Q. Study the following program:


1. class Std_Name:
2. def __init__(self, Std_firstName, Std_Phn, Std_lastName):
3. self.Std_firstName = Std_firstName
4. self. Std_PhnStd_Phn = Std_Phn
5. self. Std_lastNameStd_lastName = Std_lastName
6.
7. Std_firstName = "Wick"
8. name = Std_Name(Std_firstName, 'F', "Bob")
9. Std_firstName = "Ann"
10. name.lastName = "Nick"
11. print(name.Std_firstName, name.Std_lastName)
What will be the output of this statement?
a. Ann Bob
b. Ann Nick
c. Wick Bob
d. Wick Nick

Answer: (d) Wick Nick


Explanation: None

Q. Study the following statements:


>>> print(ord('h') - ord('z'))
What will be the output of this statement?
a. 18
b. -18
c. 17
d. -17

Answer: (b) -18


Explanation: ASCII value of h is less than the z. Hence the output of this code is 104-122, which is
equal to -18.

Q. Study the following program:


1. x = ['xy', 'yz']
2. for i in a:
3. i.upper()
4. print(a)
Which of the following is correct output of this program?
a. ['xy', 'yz']
b. ['XY', 'YZ']
c. [None, None]
d. None of these
Answer: (a) ['xy', 'yz']
Explanation: None

Q. Study the following program:


1. i = 1:
2. while True:
3. if i%3 == 0:
4. break
5. print(i)
Which of the following is the correct output of this program?
a. 123
b. 3 2 1
c. 1 2
d. Invalid syntax

Answer: (d) Invalid syntax


Explanation: Invalid syntax, because this declaration (i = 1:) is wrong.

Q. Study the following program:


1. a = 1
2. while True:
3. if a % 7 = = 0:
4. break
5. print(a)
6. a += 1
Which of the following is correct output of this program?
a. 12345
b. 1 2 3 4 5 6
c. 1 2 3 4 5 6 7
d. Invalid syntax

Answer: (b) 1 2 3 4 5 6
Explanation: None

Q. Study the following program:


1. i = 0
2. while i < 5:
3. print(i)
4. i += 1
5. if i == 3:
6. break
7. else:
8. print(0)
What will be the output of this statement?
a. 123
b. 0 1 2 3
c. 0 1 2
d. 3 2 1

Answer: (c) 0 1 2
Explanation: None

Q. Study the following program:


1. i = 0
2. while i < 3:
3. print(i)
4. i += 1
5. else:
6. print(0)
What will be the output of this statement?
a. 01
b. 0 1 2
c. 0 1 2 0
d. 0 1 2 3

Answer: (c) 0 1 2 0
Explanation: None

Q. Study the following program:


1. z = "xyz"
2. j = "j"
3. while j in z:
4. print(j, end=" ")
What will be the output of this statement?
a. xyz
b. No output
c. x y z
d. j j j j j j j..

Answer: (b) No output


Explanation: "j" is not in "xyz".

Q. Study the following program:


1. x = 'pqrs'
2. for i in range(len(x)):
3. x[i].upper()
4. print (x)
Which of the following is the correct output of this program?
a. PQRS
b. pqrs
c. qrs
d. None of these

Answer: (b) pqrs


Explanation: None

Q. Study the following program:


1. d = {0: 'a', 1: 'b', 2: 'c'}
2. for i in d:
3. print(i)
What will be the output of this statement?
a. abc
b. 0 1 2
c. 0 a 1 b 2 c
d. None of these above

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

Answer: (c) Class


Explanation: Class is not a core data type because it is a user-defined data type.

Q. What error will occur when you execute the following code?
MANGO = APPLE
a. NameError
b. SyntaxError
c. TypeError
d. ValueError

Answer: (a) NamaError


Explanation: Mango is not defined hence the name error.

Q. Study the following program:


1. def example(a):
2. aa = a + '1'
3. aa = a*1
4. return a
5. >>>example("javatpoint")
What will be the output of this statement?
a. hello2hello2
b. hello2
c. Cannot perform mathematical operation on strings
d. indentationError

Answer: (d) indentationError


Explanation: None

Q. Which of the following data types is shown below?


L = [2, 54, 'javatpoint', 5]
What will be the output of this statement?
a. Dictionary
b. Tuple
c. List
d. Stack
Answer: (c) List
Explanation: Any value can be stored in the list data type.

Q. What happens when '2' == 2 is executed?


a. False
b. Ture
c. ValueError occurs
d. TypeError occurs

Answer: (a) False


Explanation: It only evaluates to false.

Q. Study the following program:


1. try:
2. if '2' != 2:
3. raise "JavaTpoint"
4. else:
5. print("JavaTpoint has not exist")
6. except "JavaTpoint":
7. print ("JavaTpoint has exist")
What will be the output of this statement?
a. invalid code
b. JavaTpoint has not exist
c. JavaTpoint has exist
d. none of these above

Answer: (a) invalid code


Explanation: A new exception class must inherit from a BaseException, and there is no such
inheritance here.

Q. Study the following statement


z = {"x":0, "y":1}
Which of the following is the correct statement?
a. x dictionary z is created
b. x and y are the keys of dictionary z
c. 0 and 1 are the values of dictionary z
d. All of the above

Answer: (d) All of the above


Explanation: All of the above statements is correct regarding Python code.

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 ?

1.It convert array to list


2.It convert list to array
3.It convert array to array
4.Error
Answer:2

Question:
Shape() function in Numpy array is used to

1.Find the shape of the array


2.Change the shape of the array
3.Both of the above
4.None of the above
Answer:1

Question:
What is the use of the size attribute in Numpy array in python ?

1.It find the direction


2.It find the number of items
3.It find the shape
4.All of the above
Answer:2

Question:
what is the use of the zeros() function in Numpy array in python ?

1.To make a Matrix with all element 0


2.To make a Matrix with all diagonal element 0
3.To make a Matrix with first row 0
4.None of the above
Answer:1

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

Q. Python pandas was developed by?

A. Guido van Rossum


B. Travis Oliphant
C. Wes McKinney
D. Brendan Eich
View Answer
Ans : C

Explanation: Pandas is a high-level data manipulation tool developed by Wes McKinney.

Q. What will be output for the following code?

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: Retrieve a single element using index label value.

Q. What will be correct syntax for pandas series?

A. pandas_Series( data, index, dtype, copy)


B. pandas.Series( data, index, dtype)
C. pandas.Series( data, index, dtype, copy)
D. pandas_Series( data, index, dtype)
View Answer
Ans : C

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. pandas.DataFrame( data, index, dtype, copy)


B. pandas.DataFrame( data, index, rows, dtype, copy)
C. pandas_DataFrame( data, index, columns, dtype, copy)
D. pandas.DataFrame( data, index, columns, dtype, copy)
View Answer
Ans : D

Explanation: A pandas DataFrame can be created using the following constructor :


pandas.DataFrame( data, index, columns, dtype, copy)

Q. Axis 1, in panel represent?

A. minor_axis
B. major_axis
C. items
D. None of the above
View Answer
Ans : B

Explanation: major_axis : axis 1, it is the index (rows) of each of the DataFrames.

Q. Which of the following thing can be data in Pandas?

A. a python dict
B. an ndarray
C. a scalar value
D. All of the above
View Answer
Ans : D

Explanation: The passed index is a list of axis labels.

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: Seaborn has great support for pandas data objects.

Q. Why ndim is used?

A. Returns the number of elements in the underlying data.


B. Returns the Series as ndarray.
C. Returns the number of dimensions of the underlying data, by definition 1.
D. Returns a list of the axis labels
View Answer
Ans : C

Explanation: ndim : Returns the number of dimensions of the underlying data, by definition 1

Q. What will be output for the following code?

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

Explanation: size : Returns the size(length) of the series.

Q. Which of the following is false?

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.

Q. SciPy stands for?

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.

Q. Which of the following is not correct sub-packages of SciPy?

A. scipy.cluster
B. scipy.source
C. scipy.interpolate
D. scipy.signal
Ans : B

Explanation: scipy.source is not correct sub-packages of SciPy.

Q. Which of the following is true?

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

Explanation: All statement are correct.

Q. What will be output for the following code?

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. ])

Q. How to import Constants Package in SciPy?

A. import scipy.constants
B. from scipy.constants
C. import scipy.constants.package
D. from scipy.constants.package

Ans : B

Explanation: from scipy.constants is used.

Q. what is constant defined for Boltzmann constant in SciPy?

A. G
B. e
C. R
D. k

Ans : D

Explanation: k : Boltzmann constant


Q. What will be output for the following code?

from scipy import linalg


import numpy as np
a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]])
b = np.array([2, 4, -1])
x = linalg.solve(a, b)
print x
A. array([ 2., -2., 9., 6.])
B. array([ 2., -2., 9.])
C. array([ 2., -2.])
D. array([ 2., -2., 9., -9.])
Ans : B

Explanation: The above program will generate the following output : array([ 2., -2., 9.])

Q. In SciPy, determinant is computed using?

A. determinant()
B. SciPy.determinant()
C. det()
D. SciPy.det()
Ans : C

Explanation: In SciPy, this is computed using the det() function.

Q. Which of the following is false?

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

Explanation: Both statement are true.

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. What is true about Machine Learning?

A. Machine Learning (ML) is that field of computer science


B. ML is a type of artificial intelligence that extract patterns out of raw data by using an algorithm
or method.
C. The main focus of ML is to allow computer systems learn from experience without being
explicitly programmed or human intervention.
D. All of the above
Ans : D

Explanation: All statement are true about Machine Learning.

Q. ML is a field of AI consisting of learning algorithms that?

A. Improve their performance


B. At executing some task
C. Over time with experience
D. All of the above
Ans : D

Explanation: ML is a field of AI consisting of learning algorithms that : Improve their performance


(P), At executing some task (T), Over time with experience (E).

Q. p → 0q is not a?

A. hack clause
B. horn clause
C. structural clause
D. system clause
Ans : B

Explanation: p → 0q is not a horn clause.

Q. The action _______ of a robot arm specify to Place block A on block 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.

Q. A__________ begins by hypothesizing a sentence (the symbol S) and successively predicting


lower level constituents until individual preterminal symbols are written.

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.

Q. Different learning methods does not include?

A. Introduction
B. Analogy
C. Deduction
D. Memorization
Ans : A

Explanation: Different learning methods does not include the introduction.

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.

Q. Which of the following are ML methods?

A. based on human supervision


B. supervised Learning
C. semi-reinforcement Learning
D. All of the above
Ans : A

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:

A. The value of the gradient at extrema of a function is always zero


B. Depends on the type of problem
C. Both A and B
D. None of the above
Ans : A

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.

Q. Which of the following is a disadvantage of decision trees?

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.

Q. How do you handle missing or corrupted data in a dataset?


A. Drop missing rows or columns
B. Replace missing values with mean/median/mode
C. Assign a unique category to missing values
D. All of the above
Ans : D

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?

A. Normalize the data -> PCA -> training


B. PCA -> normalize PCA output -> training
C. Normalize the data -> PCA -> normalize PCA output -> training
D. None of the above
Ans : A

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.

Q. Which of the following statements about regularization is not correct?

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

Explanation: Lemmatization and stemming are the techniques of keyword normalization.

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.

Q. What is a sentence parser typically used for?

A. It is used to parse sentences to check if they are utf-8 compliant.


B. It is used to parse sentences to derive their most likely syntax tree structures.
C. It is used to parse sentences to assign POS tags to all tokens.
D. It is used to check if sentences can be parsed into meaningful tokens.
Ans : B

Explanation: Sentence parsers analyze a sentence and automatically build a syntax tree.
MCQ

CHAPTER 1 - GETTING STARTED WITH PYTHON

CLASS TEST – I

Time: 40 Min Max Marks: 20

1. Is Python case sensitive when dealing with identifiers?

a) yes

b) no

c) machine dependent

d) none of the mentioned

2. What is the maximum possible length of an identifier?

a) 31 characters

b) 63 characters

c) 79 characters

d) none of the mentioned

3. Which of the following is invalid?

a) _a = 1

b) __a = 1

c) __str__ = 1

d) none of the mentioned

4. Which of the following is an invalid variable?

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) 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

6. Which of the following is not a keyword?

a) eval

b) assert

c) nonlocal

d) pass

7. All keywords in Python are in

a) lower case

b) UPPER CASE

c) Capitalized

d) None of the mentioned

8. Which of the following is true for variable names in Python?

a) unlimited length

b) all private members must have leading and trailing underscores

c) underscore and ampersand are the only two special characters allowed

d) none of the mentioned

9. Which of the following is an invalid statement?

a) abc = 1,000,000

b) a b c = 1000 2000 3000

Page No 2
c) a,b,c = 1000, 2000, 3000

d) a_b_c = 1,000,000

10. Which of the following cannot be a variable?

a) __init__

b) in

c) it

d) on

Page No 3
MCQ

CHAPTER 2 - PYTHON FUNDAMENTALS

CLASS TEST – II

Time: 40 Min Max Marks: 20

1. Which is the correct operator for power(xy)?


a) X^y
b) X**y
c) X^^y
d) None of the mentioned

2. Which one of these is floor division?


a) /
b) //
c) %
d) None of the mentioned

3. 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

4. What is answer of this expression, 22 % 3 is?


a) 7
b) 1
c) 0
d) 5

Page No 4
5. Mathematical operations can be performed on a string. State whether true or
false.
a) True
b) False

6. 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

7. What is the output of this expression, 3*1**3?


a) 27
b) 9
c) 3
d) 1

8. Which one of the following have the same precedence?


a) Addition and Subtraction
b) Multiplication and Division
c) Both Addition and Subtraction AND Multiplication and Division
d) None of the mentioned

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

CHAPTER 3 – DATA HANDLING

CLASS TEST III

Time: 40 Min Max Marks: 20

1. Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class

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

4. Which of the following will run without errors ?

a) round(45.8)

b) round(6352.898,2,5)

c) round()

Page No 6
d) round(7463.123,2,1)

5. What is the return type of function id ?

a) int

b) float

c) bool

d) dict

6. 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

7. What error occurs when you execute?

apple = mango

a) SyntaxError

b) NameError

c) ValueError

d) TypeError

8. Carefully observe the code and give the answer.

def example(a):

a = a + '2'

a = a*2

return a

Page No 7
>>>example("hello")

a) indentation Error

b) cannot perform mathematical operation on strings

c) hello2

d) hello2hello2

9. What data type is the object below ?

L = [1, 23, ‘hello’, 1].

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

11. Which of the following results in a SyntaxError ?

a) ‘”Once upon a time…”, she said.’

b) “He said, ‘Yes!'”

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

>>>average = (grade1 + grade2) / 2

a) 85

b) 85.1

c) 95

d) 95.1

13. Select all options that print

hello-how-are-you

a) print(‘hello’, ‘how’, ‘are’, ‘you’)

b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)

c) print(‘hello-‘ + ‘how-are-you’)

d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)

14. What is the return value of trunc() ?

a) int

b) bool

c) float

d) None

15. What is the output of print 0.1 + 0.2 == 0.3?

a) True

b) False

c) Machine dependent

d) Error

16. Which of the following is not a complex number?

a) k = 2 + 3j

Page No 9
b) k = complex(2, 3)

c) k = 2 + 3l

d) k = 2 + 3J

17. What is the type of inf?

a) Boolean

b) Integer

c) Float

d) Complex

18. What does ~4 evaluate to?

a) -5

b) -4

c) -3

d) +3

19. What does ~~~~~~5 evaluate to?

a) +5

b) -11

c) +11

d) -5

20. Which of the following is incorrect?

a) x = 0b101

b) x = 0x4f5

c) x = 19023

d) x = 03964

Page No 10
MCQ

CHAPTER IV - CONDITIONAL AND ITERATIVE STATEMENTS

CLASS TEST IV

Time: 40 Min Max Marks: 20

1. What is the output of the following?

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

2. What is the output of the following?

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

3. What is the output of the following?

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

d) none of the mentioned

4. What is the output of the following?

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

5. What is the output of the following?

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

6. What is the output of the following?

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

7. What is the output of the following?

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 …

8. What is the output of the following?

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

9. What is the output of the following?

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

Page No 14
10. What is the output of the following?

True = False

while True:

print(True)

break

a) True

b) False

c) None

d) none of the mentioned

11. What is the output of the following?

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

12. What is the output of the following?

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

13. What is the output of the following?

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

14. What is the output of the following?

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

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

16. What is the output of the following?

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

17. What is the output of the following?

x = 'abcd'

for i in range(len(x)):

x = 'a'

print(x)

Page No 17
a) a

b) abcd abcd abcd

c) a a a a

d) none of the mentioned

18. What is the output of the following?

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

19. What is the output of the following?

x = 123

for i in x:

print(i)

a) 1 2 3

b) 123

c) error

d) none of the mentioned

20 . What is the output of the following?

d = {0: 'a', 1: 'b', 2: 'c'}

for i in d:

print(i)

Page No 18
a) 0 1 2

b) a b c

c) 0 a 1 b 2 c

d) none of the mentioned

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

Time: 40 Min Max Marks: 20

1. What is the output when following statement is executed ?

>>>"a"+"bc"

a) a

b) bc

c) bca

d) abc

2. What is the output when following statement is executed ?

>>>"abcd"[2:]

a) a

b) ab

c) cd

d) dc

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

Page No 21
4. What is the output when following code is executed ?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a) olleh

b) hello

c) h

d) o

5. What arithmetic operators cannot be used with strings ?

a) +

b) *

c) –

d) All of the mentioned

6. What is the output when following code is executed ?

>>>print r"\nhello"

The output is

a) a new line and hello

b) \nhello

c) the letter r and then hello

d) error

7. What is the output when following statement is executed ?

>>>print('new' 'line')

a) Error

b) Output equivalent to print ‘new\nline’

Page No 22
c) newline

d) new line

8. What is the output when following statement is executed ?

>>> print(‘x\97\x98’)

a) Error

b) 97

98

c) x\97

d) \x97\x98

9. What is the output when following code is executed ?

>>>str1="helloworld"

>>>str1[::-1]

a) dlrowolleh

b) hello

c) world

d) helloworld

10. print(0xA + 0xB + 0xC) :

a) 0xA0xB0xC

b) Error

c) 0x22

d) 33

11. What is the output of the following?

print("xyyzxyzxzxyy".count('yy'))

a) 2

b) 0

Page No 23
c) error

d) none of the mentioned

12. What is the output of the following?

print("xyyzxyzxzxyy".count('yy', 1))

a) 2

b) 0

c) 1

d) none of the mentioned

13. What is the output of the following?

print("xyyzxyzxzxyy".count('yy', 2))

a) 2

b) 0

c) 1

d) none of the mentioned

14. What is the output of the following?

print("xyyzxyzxzxyy".count('xyy', 0, 100))

a) 2

b) 0

c) 1

d) error

15. What is the output of the following?

print("xyyzxyzxzxyy".count('xyy', 2, 11))

a) 2

b) 0

c) 1

d) error

16. What is the output of the following?

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

CHAPTER VI - CHAPTER VI DEBUGGING PROGRAMS

CLASS TEST VI

Time: 40 Min Max Marks: 20

1. Examination of the program step by step is called ______________

a) Controlling

b) Tracing

c) Stepping

d) Testing

2. The examination of changing values of variables is called stepping.

a) True

b) False

3. A freeware GNU Debugger is __________

a) GDB

b) GNB

c) FDB

d) FNB

4. Which of the following is written for getting help in GDB?

a) he

b) h

c) assist

d) assistant

5. h command gives ___________

a) A list of all the commands starting from h

Page No 26
b) Describes all the commands

c) Displays a short description of the command

d) Displays all the programs

6. ____________ creates an inferior process that runs your program.

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

8. ‘set args ‘ without arguments can ___________

a) initialize all the arguments

b) remove all the arguments

c) no change

d) show all the arguments

9. Which is not involved in debugging?

a) Identifying

b) Isolating

c) Test

d) Fixing

Page No 27
10. run > outfile command is used to _________

a) direct output to the file outfile

b) jump to a file outfile

c) enter a file outfile

d) edit a file outfile

Page No 28
MCQ

CHAPTER VII - LISTS

CLASS TEST VII

Time: 40 Min Max Marks: 20

1. Process of removing errors called

a) Error Free

b) Debug

c) Syntax Error

d) Exception

2. Which of the following commands will create a list?


a) list1 = list()
b) list1 = [].
c) list1 = list([1, 2, 3])
d) all of the mentioned

3. What is the output when we execute list(“hello”)?


a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’].
b) [‘hello’].
c) [‘llo’].
d) [‘olleh’].

4. Suppose list Example is [‘h’,’e’,’l’,’l’,’o’], what is len(list Example)?


a) 5
b) 4
c) None
d) Error

5. Suppose list1 is [2445, 133, 12454, 123], what is max(list1) ?


a) 2445
b) 133
c) 12454
d) 123

6. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?


a) 3
b) 5
c) 25
d) 1

Page No 29
7. Suppose list1 is [1, 5, 9], what is sum(list1) ?
a) 1
b) 9
c) 15
d) Error

8. To shuffle the list(say list1) what function do we use ?


a) list1.shuffle ()
b) shuffle(list1)
c) random.shuffle(list1)
d) random.shuffleList(list1)

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].

12. What is the output when following code is executed ?

>>>names = ['Amir', 'Bear', 'Charlton', 'Daman']

>>>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 ?

names1 = ['Amir', 'Bear', 'Charlton', 'Daman']

names2 = names1

names3 = names1[:]

names2[0] = 'Alice'

names3[1] = 'Bob'

sum = 0

for ls in (names1, names2, names3):

if ls[0] == 'Alice':

sum += 1

if ls[1] == 'Bob':

sum += 10

print sum

a) 11

b) 12

c) 21

d) 22

14. Suppose list1 is [1, 3, 2], What is list1 * 2 ?

a) [2, 6, 4].

b) [1, 3, 2, 1, 3].

c) [1, 3, 2, 1, 3, 2] .

D) [1, 3, 2, 3, 2, 1].

15. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is :

a) [0, 1, 2, 3].

b) [0, 1, 2, 3, 4].

c) [0.0, 0.5, 1.0, 1.5].

Page No 31
d) [0.0, 0.5, 1.0, 1.5, 2.0].

16. What is the output when following code is executed ?

>>>list1 = [11, 2, 23]

>>>list2 = [11, 2, 2]

>>>list1 < list2 is

a) True

b) False

c) Error

d) None

17. To add a new element to a list we use which command ?

a) list1.add(5)

b) list1.append(5)

c) list1.addLast(5)

d) list1.addEnd(5)

18. To insert 5 to the third position in list1, we use which command ?

a) list1.insert(3, 5)

b) list1.insert(2, 5)

c) list1.add(3, 5)

d) list1.append(3, 5)

19. To remove string “hello” from list1, we use which command ?

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

CHAPTER VIII - TUPLES

CLASS TEST VII

Time: 40 Min Max Marks: 20

1. Which of the following is a Python tuple?

a) [1, 2, 3].

b) (1, 2, 3)

c) {1, 2, 3}

d) {}

2. Suppose t = (1, 2, 4, 3), which of the following is incorrect?

a) print(t[3])

b) t[3] = 45

c) print(max(t))

d) print(len(t))

3. What will be the output?

>>>t=(1,2,4,3)

>>>t[1:3]

a) (1, 2)

b) (1, 2, 4)

c) (2, 4)

d) (2, 4, 3)

4. What will be the output?

>>>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)

5. What will be the output?

>>>t = (1, 2, 4, 3, 8, 9)

>>>[t[i] for i in range(0, len(t), 2)]

a) [2, 3, 9].

b) [1, 2, 4, 3, 8, 9].

c) [1, 4, 8].

d) (1, 4, 8)

6. What will be the output?

d = {"john":40, "peter":45}

d["john"]

a) 40

b) 45

c) “john”

d) “peter”

7. What will be the output?

>>>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

9. What will be the output?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

a) 1

b) 2

c) 5

d) Error

10. What will be the output?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

sum = 0

for k in numberGames:

sum += numberGames[k]

print len(numberGames) + sum

Page No 36
a) 30

b) 24

c) 33

d) 12

11. What is the data type of (1)?

a) Tuple

b) Integer

c) List

d) Both tuple and integer

12. If a=(1,2,3,4), a[1:-1] is

a) Error, tuple slicing doesn’t exist

b) [2,3].

c) (2,3,4)

d) (2,3)

13. What is the output of the following code?

>>> a=(1,2,(4,5))

>>> b=(1,2,(3,4))

>>> a<b

a) False

b) True

c) Error, < operator is not valid for tuples

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’)

b) * Operator not valid for tuples

c) (‘CheckCheckCheck’)

d) Syntax error

15. What is the output of the following code?

>>> 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)

d) Error as tuple is immutable

16. What is the output of the following code?

>>> a=(2,3,4)

>>> sum(a,3)

a) Too many arguments for sum() method

b) The method sum() doesn’t exist for tuples

c) 12

d) 9

17. Is the following piece of code valid?

>>> a=(1,2,3,4)

>>> del a

a) No because tuple is immutable

b) Yes, first element in the tuple is deleted

c) Yes, the entire tuple is deleted

Page No 38
d) No, invalid syntax for del method

18. What type of data is: a=[(1,1),(2,4),(3,9)]?

a) Array of tuples

b) List of tuples

c) Tuples of lists

d) Invalid type

19. What is the output of the following piece of code?

>>> a=(0,1,2,3,4)

>>> b=slice(0,2)

>>> a[b]

a) Invalid syntax for slicing

b) [0,2].

c) (0,1)

d) (0,2)

20. Is the following piece of code valid?

>>> a=(1,2,3)

>>> b=('A','B','C')

>>> c=zip(a,b)

a) Yes, c will be ((1,2,3),(‘A’,’B’,’C’))

b) Yes, c will be ((1,2,3),(‘A’,’B’,’C’))

c) No because tuples are immutable

d) No because the syntax for zip function isn’t valid

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

Time: 40 Min Max Marks: 20

1. Which of the following statements create a dictionary?

a) d = {}

b) d = {“john”:40, “peter”:45}

c) d = {40:”john”, 45:”peter”}

d) All of the mentioned

2. Read the code shown below carefully and pick out the keys?

d = {"john":40, "peter":45}

a) “john”, 40, 45, and “peter”

b) “john” and “peter”

c) 40 and 45

d) d = (40:”john”, 45:”peter”)

3. What will be the output?

d = {"john":40, "peter":45}

"john" in d

a) True

b) False

c) None

d) Error

4. What will be the output?

d1 = {"john":40, "peter":45}

Page No 40
d2 = {"john":466, "peter":45}

d1 == d2

a) True

b) False

c) None

d) Error

5. What will be the output?

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

d1 > d2

a) True

b) False

c) Error

d) None

6. What is the output?

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)

8. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary


which command do we use?

a) d.size()

b) len(d)

c) size(d)

d) d.len()

9. What will be the output?

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)

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

11. Which of these about a dictionary is false?

a) The values of a dictionary can be accessed using keys

b) The keys of a dictionary can be accessed using values

c) Dictionaries aren’t ordered

Page No 42
d) Dictionaries are mutable

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 is the output of the following code?

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 is the output of the following piece of code?

a={1:"A",2:"B",3:"C"}

print(a.get(1,4))

a) 1

b) A

c) 4

d) Invalid syntax for get method

15. What is the output of the following code?

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

16. What is the output of the following code?

a={1:"A",2:"B",3:"C"}

print(a.setdefault(3))

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b) C

c) {1: 3, 2: 3, 3: 3}

d) No method called setdefault() exists for dictionary

17. What is the output of the following code?

a={1:"A",2:"B",3:"C"}

a.setdefault(4,"D")

print(a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}.

b) None.

c) Error.

d) [1,3,6,10].

18. What is the output of the following code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

Page No 44
b) Method update() doesn’t exist for dictionaries

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d) {4: ‘D’, 5: ‘E’}

19. What is the output of the following code?

a={1:"A",2:"B",3:"C"}

b=a.copy()

b[2]="D"

print(a)

a) Error, copy() method doesn’t exist for dictionaries

b) {1: ‘A’, 2: ‘B’, 3: ‘C’}

c) {1: ‘A’, 2: ‘D’, 3: ‘C’}

d) “None” is printed

20. What is the output of the following code?

a={1:"A",2:"B",3:"C"}

a.clear()

print(a)

a) None

b) { None:None, None:None, None:None}

c) {1:None, 2:None, 3: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

CHAPTER X - UNDERSTANDING SORTING

CHAPTER XI - STATE AND TRANSITIONS

CLASS TEST X

Time: 40 Min Max Marks: 20

1. Which of the following is not a stable sorting algorithm?

a) Insertion sort
b) Selection sort
c) Bubble sort
d) Merge sort

ANSWER: B

2. Which of the following is a stable sorting algorithm?

a) Merge sort
b) Typical in-place quick sort
c) Heap sort
d) Selection sort

ANSWER: A

3. Which of the following is not an in-place sorting algorithm?

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

6. Consider the situation in which assignment operation is very costly. Which


of the following sorting algorithm should be performed so that the number of
assignment operations is minimized in general?

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

8. Which of the following sorting algorithm is in-place

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

11. Merge sort uses

a) Divide-and-conquer
b) Backtracking
c) Heuristic approach
d) Greedy approach

ANSWER: A

Page No 48
MCQ

CHAPTER XII - COMPUTER OVERVIEW

CLASS TEST XII

Time: 40 Min Max Marks: 20

1. MSI stands for

a. Medium Scale Integrated Circuits b. Medium System Integrated Circuits

c. Medium Scale Intelligent Circuit d. Medium System Intelligent Circuit

2. The capacity of 3.5 inch floppy disk is

a. 1.40 MB b. 1.44 GB c. 1.40 GB d. 1.44 MB

3. EBCDIC stands for

a. Extended Binary Coded Decimal Interchange Code

b. Extended Bit Code Decimal Interchange Code

c. Extended Bit Case Decimal Interchange Code

d. Extended Binary Case Decimal Interchange Code

4. Which of the following is a part of the Central Processing Unit?

a. Printer b. Key board

c. Mouse d. Arithmetic & Logic unit

5. Where are data and programme stored when the processor uses them?

a. Main memory b. Secondary memory

c. Disk memory d. Programme memory

6. . ............... represents raw facts, where-as................. is data made meaningful.

a. Information, reporting b. Data, information

c. Information, bits d. Records, bytes

7. Which programming languages are classified as low level languages?

a. BASIC, COBOL, Fortran b. Prolog

c. C, C++ d. Assembly languages

Page No 49
8. Which of the following is a storage device?

a. Tape b. Hard Disk

c. Floppy Disk d. All of the above

9. A normal CD- ROM usually can store up to _________ _data?

a. 680 KB b. 680 Bytes

c. 680 MB d. 680 GB

10 What is a light pen?

a. Mechanical Input device b. Optical input device

c. Electronic input device d. Optical output device

11. ASCII stands for

a. American Stable Code for International Interchange

b. American Standard Case for Institutional Interchange

c. American Standard Code for Information Interchange

d. American Standard Code for Interchange Information

12. The computer size was very large in

a. First Generation b. Second Generation

c. Third Generation d. Fourth Generation

13. The output quality of a printer is measured by

a. Dot per inch b. Dot per sq. inch

c. Dots printed per unit time d. All of above

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?

a. Keyboard b. Mouse c. Card reader d. Any of these

16. 1 Byte =?

a. 8 bits b. 4 bits c. 2 bits d. 9 bits

17. SMPS stands for

a. Switched mode Power Supply b. Start mode power supply

c. Store mode power supply d. Single mode power supply

18. BIOS stands for


a. Basic Input Output system b. Binary Input output system
c. Basic Input Off system d. all the above

19. Data becomes ................ when it is presented in a format that people can
understand and use

a. Processed b. Graphs c. Information d. Presentation

20. Which of the following are the functions of a operating system

a. Allocates resources b. Monitors Activities

c. Manages disks and files d. All of the above

Page No 51
MCQ

CHAPTER XIII - DATA REPRESENTATION

CLASS TEST XIII

Time: 40 Min Max Marks: 20

1 ASCII code is a ……… bit code.

a) 1 b) 2 c) 7 d) 8

2 8421 codes is also called as.

a) Gray code b) ASCII code c) excess 3-code d) BCD code

3 The binary system, 1+1=…………

(a) 2 (b) 0 (c) 1 (d) none of these

4 110+110=…………

(a) 2 (b) 0 (c) 1 (d) none of these

5 The digital system usually operated on ………system.

(a) binary (b) decimal (c)octal (d) hexadecimal

6 The binary system use powers of……….for positional values.

(a) 2 (b)10 (c) 8 (d)16

7 After counting 0, 1, 10, 11, the next binary number is

(a) 12 (b) 100 (c)101 (d) 110

8. The 2’s complement of 10002 is

(a)0111 (b)0101 (c) 1000 (d)0001

9. 110100112= ?16

a) D316 b) A316 c) B316 d) D216

10 25?10= ?2__________

a) 100012 b) 110012 c) 110002 d) 101012

Page No 52
MCQ

CHAPTER XIV - BOOLEAN ALGEBRA

CLASS TEST XIV

Time: 40 Min Max Marks: 20

1 In logic algebra, variables can assume only two values:either……….or 1.


(a) 2 (b) 0 (c) 3 (d) 4
2 The………. gate is also called any-or-all gate.
(a) OR (b) AND (c) NOT (d) EX-OR
3 A logic gate is an electronic circuit which
(a) makes logic decisions (b) allows electron flow only in one direction
(c) works on binary algebra (d) alternates between 0&1 values
4. In positive logic, logic gate 1 corresponds to
(a) positive voltage (b) higher voltage level
(c) zero voltage level (d) lower voltage level
5. In negative logic, the logic state 1 corresponds to
(a) negative logic (b) zero voltage
(c) more negative voltage (d) lower voltage level
6. The output of a 2-input OR the gate is 0 only when it’s
(a) both inputs are 0 (b) either input is 1
(c) both inputs are 1 (d) either input is 0
7. In Boolean algebra , A+ A= -----------
a)A b)1 c)0 d)None of these
8. In Boolean algebra , A . A=-----------
a) A2 b) A c)2A d)1
9. In Boolean algebra A+ AB =-----------
a) B b) A c)AB d)A+B
10. When an input electrical signal A=10100 is applied to a NOT gate, it’s output
Signal is
(a) 01011 (b) 10101 (c) 10100 (d)00101

Page No 53
MCQ

CHAPTER XV

INSIGHT INTO PROGRAM EXECUTION

CLASS TEST XV

Time: 40 Min Max Marks: 20

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

CHAPTER XVI - RELATIONAL DATABASE

CLASS TEST XVI

Time: 40 Min Max Marks: 20

1 In the relational modes, cardinality is termed as:

(A) Number of tuples. (B) Number of attributes.

(C) Number of tables. (D) Number of constraints.

Ans: A

2 The view of total database content is

(A) Conceptual view. (B) Internal view.

(C) External view. (D) Physical View.

Ans: A

3. Cartesian product in relational algebra is

(A) a Unary operator. (B) a Binary operator.

(C) a Ternary operator. (D) not defined.

Ans: B Cartesian product in relational algebra is a binary operator.

(It requires two operands. e.g., P X Q)

4. DML is provided for

(A) Description of logical structure of database.

(B) Addition of new structures in the database system.

(C) Manipulation & processing of database.

(D) Definition of physical structure of database system.

Ans: C DML is provided for manipulation & processing of database.

(Data stored in the database is processed or manipulated using data manipulation

language commands as its name)

Page No 55
5. ‘AS’ clause is used in SQL for

(A) Selection operation. (B) Rename operation.

(C) Join operation. (D) Projection operation.

Ans: B ‘AS’ clause is used in SQL for rename operation.

(e.g., SELECT ENO AS EMPLOYEE_NO FROM EMP)

6. Architecture of the database can be viewed as

(A) two levels. (B) four levels.

(C) three levels. (D) one level.

Ans: C

7. In a relational model, relations are termed as

(A) Tuples. (B) Attributes

(C) Tables. (D) Rows.

Ans:c

8 The database schema is written in

(A) HLL (B) DML

(C) DDL (D) DCL

Ans: C

9. An entity set that does not have sufficient attributes to form a primary key is a

(A) strong entity set. (B) weak entity set.

(C) simple entity set. (D) primary entity set.

10. A relational database developer refers to a record as

(A) a criteria. (B) a relation.

(C) a tuple. (D) an attribute.

Ans: C

Page No 56
MCQ

CHAPTER XVII - SIMPLE QUERIES IN SQL,

CLASS TEST XVII

Time: 40 Min Max Marks: 20

1. The statement in SQL which allows to change the definition of a table is

(A) Alter. (B) Update.

(C) Create. (D) select.

Ans: A

2. The statement in SQL which allows to change the definition of a table is

(A) Alter. (B) Update.

(C) Create. (D) select.

Ans: A

3. Key to represent relationship between tables is called

(A) Primary key (B) Secondary Key

(C) Foreign Key (D) None of these

Ans: C

4. _______ produces the relation that has attributes of R1 and R2

(A) Cartesian product (B) Difference

(C) Intersection (D) Product

Ans: A

5. It is better to use files than a DBMS when there are

(A) Stringent real-time requirements.

(B) Multiple users wish to access the data.

(C) Complex relationships among data.

(D) All of the above.

Ans: B

6. The conceptual model is

Page No 57
(A) dependent on hardware.

(B) dependent on software.

(C) dependent on both hardware and software .

(D) independent of both hardware and software.

Ans: D

7. What is a relationship called when it is maintained between two entities?

(A) Unary (B) Binary

(C) Ternary (D) Quaternary

Ans: B

8. Which of the following operation is used if we are interested in only certain


columns of a table?

(A) PROJECTION (B) SELECTION

(C) UNION (D) JOIN

Ans: A

9 Which of the following is a valid SQL type?

(A) CHARACTER (B) NUMERIC

(C) FLOAT (D) All of the above

Ans: D

10. The RDBMS terminology for a row is

(A) tuple. (B) relation.

(C) attribute. (D) degree.

Ans: A

Page No 58
MCQ

CHAPTER XVIII - TABLE CREATION AND DATA MANIPULATION

CLASS TEST XVIII – (TEST 1)

Time: 40 Min Max Marks: 20

1. The full form of DDL is

(A Dynamic Data Language (B) Detailed Data Language

(C) Data Definition Language (D) Data Derivation Language

Ans: C

2. Which of the following is a legal expression in SQL?

(A) SELECT NULL FROM EMPLOYEE;

(B) SELECT NAME FROM EMPLOYEE;

(C) SELECT NAME FROM EMPLOYEE WHERE SALARY = NULL;

(D) None of the above

Ans: B

3. Which of the following is a comparison operator in SQL?

(A) = (B) LIKE

(C) BETWEEN (D) All of the above

Ans: D

4. A set of possible data values is called

(A) attribute. (B) degree.

(C) tuple. (D) domain.

Ans: D

5. NULL is

(A) the same as 0 for integer

(B) the same as blank for character

(C) the same as 0 for integer and blank for character

(D) not a value

Page No 59
Ans: D

6. Write down the syntax of update command

7. Write down the syntax of insert into command

8. Write an example to delete all the records from the table

9. Give an example to Alter the table using alter command example

10. Give Example for dropping a table

Page No 60
MCQ

CHAPTER XVIII - TABLE CREATION AND DATA MANIPULATION COMMANDS

CLASS TEST XVIII ( TEST 2)

Time: 40 Min Max Marks: 20

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

CHAPTER XIX - TABLE JOINS AND INDEXES IN SQL

CLASS TEST XIX

Time: 40 Min Max Marks: 20

1. What is join? Write a SQL command


2. What is cross join? Write a SQL command
3. What is left join? Write a SQL command
4. What is right join? Write a SQL command
5. What is Natural Join? Write a SQL command
6. What is equi join? Write a SQL command
7. What are table indexes? Write a SQL command
8. How left join is different from natural join? Write a SQL command
9. How cross join is different from natural join? Write a SQL command
10. Write a SQL command to create an index on hiredate field in table emp note
that table already exists.

Page No 62
MCQ

CHAPTER XX - BASICS OF NOSQL DATABASE

CLASS TEST XX

Time: 40 Min Max Marks: 20

1. What are the types of No SQL databases?


2. List the Advantages of No SQL databases
3. List the Disadvantages of NoSQL databases
4. What is collection?
5. What is Document?
6. What is reference?
7. What is CRUD?
8. Write db.collection.insert() syntax and example
9. Write db.collection.insertOne() syntax and example
10. Write db.collection.insertMany() syntax and example
11. Write db.collection.update() syntax and example
12. Write db.collection.save() syntax and example
13. Write db.collection.remove() syntax and example
14. Write db.collection.find() syntax and example
15. Write db.collection.findOne() syntax and example

Page No 63
MCQ

CHAPTER XXI – CYBER SAFTY

CLASS TEST XXI

Time: 40 Min Max Marks: 20

1. What is cyber safety?


2. What is Cyber Stalking
3. What is identity theft?
4. What is Cyber Troll?
5. What is Cyber Bullying?

Page No 64
MCQ

CHAPTER XXI – ONLINE ACCESS AND CYBER SAFETY

CLASS TEST XXII

Time: 40 Min Max Marks: 20

1. What are PC Intrusions?

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

Q1. Is Python case sensitive when dealing with identifiers?

A. Yes
B. No

Q2. Is Python case sensitive when dealing with identifiers?

A. yes
B. no
C. machine dependent
D. none of the mentioned

Q3. What is the maximum possible length of an identifier?

A. 79 characters
B. 31 characters
C. 63 characters
D. none of the mentioned

Q4. Which of the following is an invalid variable?

A. foo
B. my_string_1
C. 1st_string
D. _

Q5. Which of the following is not a keyword?

A. pass
B. assert
C. nonlocal
D. eval

Q6. Which of the following is invalid?


A. __str__ = 1
B. _a = 1
C. __a = 1
D. none of the mentioned

Q7. All keywords in Python are in _________

A. UPPER CASE
B. Capitalized
C. lower case
D. None of the mentioned

Q8. Which of the following is an invalid statement?

A. a b c = 1000 2000 3000


B. a,b,c = 1000, 2000, 3000
C. abc = 1,000,000
D. a_b_c = 1,000,000

Q9. Which of the following cannot be a variable?

A. __init__
B. in
C. it
D. on

Q10. Which one of these is floor division?

A. //
B. /
C. %
D. None of the mentioned

Q11. What is the answer to this expression, 22 % 3 is?

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

Q14. Which of these in not a core data type?

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

Q16. Which of the following will run without errors?

A. round(45.8)
B. round(6352.898,2,5)
C. round()
D. round(7463.123,2,1)

Q17. What is the return type of function id?

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

Q19. Which of the following results in a SyntaxError?

A. ‘3\’
B. “He said, ‘Yes!'”
C. ‘”Once upon a time…”, she said.’
D. ”’That’s okay”’

Q20. What is the output of print 0.1 + 0.2 == 0.3?

A. True
B. False
C. Machine dependen
D. Error

Q21. 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

Q22. What is the type of inf?

A. Complex
B. Float
C. Boolean
D. Integer

Q23. What does ~4 evaluate to?

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

Q25. What does 3 ^ 4 evaluate to?

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

Q28. Which of the following expressions results in an error?

A. float(‘10’)
B. int(’10.8’)
C. int(‘10’)
D. float(’10.8’)

Q29. What will be the output of the following Python expression?

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

Q32. What will be the output of the following Python code?

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

Q34. The expression shown below results in an error.

A. True
B. False

Q35. What will be the output of the following Python code?

A. {‘san’, ‘foundry’}
B. san foundry
C. sanfoundry
D. Error
Q36. Select the valid option for the following Output ?

A. Canvas.Create_text(text= ''Hello! ''


B. Canvas.Create_text(30 , 40, text= ''Hello! '' ,filled= ''green ''
C. Canvas.Create_text(text= ''Hello! '' ,textcolor= ''Green''
D. Canvas.Create_text(30 , 40, text= ''Hello!''

Q37. What will be the output of the following Python code if the input entered is 6?

A. Bye (printed once)


B. Invalid (printed once)
C. No output
D. Bye (printed infinite number of times)

Q38. Which of the following is not a standard exception in Python?

A. NameError
B. AssignmentError
C. IOError
D. ValueError

Q39. An exception is ____________

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

Please Visit interviewmocks.com to download more pdfs


By OnlineInterviewQuestions.com
Python MCQ Quiz

Take Python Quiz To test your Knowledge


Below are few Python MCQ test that checks your basic knowledge of Python. This Python Test contains
around 20 questions of multiple choice with 4 options. You have to select the right answer to a question. You
can see the correct answer by clicking view answer link.

Also, Read Best Python Flask interview questions.

Q1. Which of the following is the use of id() function in python?

A. Every object doesn’t have a unique id


B. Id returns the identity of the object
C. All of the mentioned
D. None of the mentioned

Q2. Is Python case sensitive when dealing with identifiers?

A. yes
B. no

Q3. All keywords in Python are in

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

Q6. What is the return type of function id?

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. Hello ‘foo’ and foo


B. Hello foo and foo
C. Hello foo and ‘bin’
D. Error

Q8. Which of the following data types is not supported in python ?

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

Q10. Select the reserved keyword in python-


A. else
B. raise
C. import
D. All of the above

Q11. Are nested if-else are allowed in Python?

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

Q14. The format function, when applied on a string returns :

A. list
B. bool
C. int
D. str

Q15. Which statement is correct....??

A. List is mutable & Tuple is immutable


B. List is immutable & Tuple is mutable
C. Both are Mutable.
D. Both are Immutable

Q16. What is the maximum possible length of an identifier?

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

Q18. What will be the output of 7^10 in python?

A. 13
B. 15
C. 2
D. None of these

Q19. 19 % 2 in python

A. 2
B. 17
D. None of these

Q20. Which of the following has more precedance?

A. /
B. +
C. ()
D. -
Q21. Is Tuple mutable?

A. yes
B. no

Please Visit OnlineInterviewquestions.com to download more pdfs


Is Python case sensitive when dealing with identifiers?
a) yes
b) no
c) machine dependent
d) none of the mentioned

Answer: a

2. What is the maximum possible length of an identifier?


a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned

Answer: d

Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned

Answer: d

Which of the following is an invalid variable?


a) my_string_1
b) 1st_string
c) foo
d) _

Answer: b

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

Answer: a

. Which of the following is not a keyword?


a) eval
b) assert
c) nonlocal
d) pass

Answer: a

All keywords in Python are in _________


a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

Answer: d

Which of the following is true for variable names in Python?


a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special characters allowed
d) none of the mentioned

Answer: a

Which of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000
View Answer

Answer: b

Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on

Answer: b

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
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

Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class

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

What will be the output of the following Python code?

advertisement

1.>>>str="hello"
2.>>>str[:2]
3.>>>

a) he
b) lo
c) olleh
d) hello

Answer: a

Which of the following will run without errors?


a) round(45.8)
b) round(6352.898,2,5)
c) round()
d) round(7463.123,2,1)

Answer: a

What is the return type of function id?


a) int
b) float
c) bool
d) dict

Answer: a

In python we do not specify types, it is directly interpreted by the compiler, so consider


the following operation to be performed.

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

What will be the output of the following Python code snippet?

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

What data type is the object below?

L = [1, 23, 'hello', 1]

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

Which of the following results in a SyntaxError?


a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”

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

What is the average value of the following Python code snippet?

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

Select all options that print.

hello-how-are-you

a) print(‘hello’, ‘how’, ‘are’, ‘you’)


b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘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

What is the type of inf?


a) Boolean
b) Integer
c) Float
d) Complex
Answer: c
What does ~4 evaluate to?
a) -5
b) -4
c) -3
d) +3
Answer: a
What does ~~~~~~5 evaluate to?
a) +5
b) -11
c) +11
d) -5
Answer: a
Which of the following is incorrect?
a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964
Answer: d
What is the result of cmp(3, 1)?
a) 1
b) 0
c) True
d) False
Answer: a
Which of the following is incorrect?
a) float(‘inf’)
b) float(‘nan’)
c) float(’56’+’78’)
d) float(’12+34′)
Answer: d
What is the result of round(0.5) – round(-0.5)?
a) 1.0
b) 2.0
c) 0.0
d) Value depends on Python version
Answer: d
What does 3 ^ 4 evaluate to?
a) 81
b) 12
c) 0.75
d) 7
Answer: d
The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.
a) True
b) False
Answer: a
What will be the value of the following Python expression?

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

. What is the value of the following expression?

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

What is the value of the following expression?

float(22//3+3/3)

a) 8
b) 8.0
c) 8.3
d) 8.33

Answer: b

What will be the output of the following Python expression?

print(4.00/(2.0+2.0))
a)Error
b)1.0
c)1.00
d) 1

Answer: b

What will be the value of X in the following Python expression?

X = 2+9*((3*12)-8)/10
a) 30.0
b) 30.8
c) 28.4
d) 27.2

Answer: d

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

Answer: c

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)

Answer: a

Which among the following list of operators has the highest precedence?

+, -, **, %, /, <<, >>, |


a) <<, >>
b) **
c) |
d) %
Answer: b
What will be the value of the following Python expression?

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

What will be the output of the following Python expression?

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

What will be the output of the following Python expression?

~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

What will be the output of the following Python code snippet?

['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?

l=[1, 0, 2, 0, 'hello', '', []]


list(filter(bool, l))

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?

if (9 < 0) and (0 < -9):


print("hello")
elif (9 > 0) or False:
print("good")
else:
print("bad")

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?

not(10<20) and not(10>30)

a) True
b) False
c) Error
d) No output

What will be the output of the following Python code snippet?

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

What will be the output of the following Python code snippet?


x=3.3456789
'%-6.2f | %05.2f | %+06.1f' %(x, x, x)
a) ‘3.35 | 03.35 | +003.3’
b) ‘3.3456789 | 03.3456789 | +03.3456789’
c) Error
d) ‘3.34 | 03.34 | 03.34+’

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

What will be the output of the following Python code snippet?

'%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'}


a) Error
b) No output
c) ‘1 more foods’
d) ‘1 more spam’

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?

s='{0}, {1}, and {2}'


s.format('hello', 'good', 'morning')
a) ‘hello good and morning’
b) ‘hello, good, morning’
c) ‘hello, good, and morning’
d) Error
Answer: c

What will be the output of the following Python code?

s='%s, %s & %s'


s%('mumbai', 'kolkata', 'delhi')
a) mumbai kolkata & delhi
b) Error
c) No output
d) ‘mumbai, kolkata & delhi’

Answer: d
What will be the output of the following Python code?

t = '%(a)s, %(b)s, %(c)s'


t % dict(a='hello', b='world', c='universe')
a) ‘hello, world, universe’
b) ‘hellos, worlds, universes’
c) Error
d) hellos, world, universe

Answer: a
What will be the output of the following Python code?

'{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])


a) Error
b) ‘2.5, 10, [1, 2]’
c) 2.5, 10, 1, 2
d) ’10, 2.5, [1, 2]’

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

What will be the output of the following Python code?

'%x %d' %(255, 255)


a) ‘ff, 255’
b) ‘255, 255’
c) ‘15f, 15f’
d) Error
Answer: a

The output of the two codes shown below is the same.

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

What will be the output of the following Python code?

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?

hex(255), int('FF', 16), 0xFF


a) [0xFF, 255, 16, 255]
b) (‘0xff’, 155, 16, 255)
c) Error
d) (‘0xff’, 255, 255)

Answer: d

The output of the two codes shown below is the same.


i. bin((2**16)-1)
ii. '{}'.format(bin((2**16)-1))
a) True
b) False

Answer: a

What will be the output of the following Python code?

'{a}{b}{a}'.format(a='hello', b='world')
a) ‘hello world’
b) ‘hello’ ‘world’ ‘hello’
c) ‘helloworldhello’
d) ‘hello’ ‘hello’ ‘world’

Answer: c

What will be the output of the following Python code?

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?

'The {} side {1} {2}'.format('bright', 'of', 'life')


a) Error
b) ‘The bright side of life’
c) ‘The {bright} side {of} {life}’
d) No output

Answer: a
What will be the output of the following Python code?

'{0:f}, {1:2f}, {2:05.2f}'.format(1.23456, 1.23456, 1.23456)


a) Error
b) ‘1.234560, 1.22345, 1.23’
c) No output
d) ‘1.234560, 1.234560, 01.23’

Answer: d

What will be the output of the following Python code?


'%.2f%s' % (1.2345, 99)
a) ‘1.2345’, ‘99’
b) ‘1.2399’
c) ‘1.234599’
d) 1.23, 99

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

What will be the output of the following Python function?

def f(p, q):


return p%q
f(0, 2)
f(2, 0)
a)

b)
Zero Division Error

Zero Division Error

c)

Zero Division Error

d)

Zero Division Error

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

Zero Division Error

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

What will be the output of the following Python code?

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

What will be the output of the following Python code?

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

What will be the output of the following Python code?

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

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

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

What will be the output of the following Python code?

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

What will be the output of the following Python code snippet?

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

What will be the output of the following Python code?

d = {0: 'a', 1: 'b', 2: 'c'}


for i in d:
print(i)
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned

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?

d = {0: 'a', 1: 'b', 2: 'c'}


for x, y in d.items():
print(x, y)
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned

Answer: c
What will be the output of the following Python code?

d = {0: 'a', 1: 'b', 2: 'c'}


for x in d.keys():
print(d[x])
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned

Answer: b
What will be the output of the following Python code?

d = {0: 'a', 1: 'b', 2: 'c'}


for x in d.values():
print(x)
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned

Answer: b
What will be the output of the following Python code?

d = {0: 'a', 1: 'b', 2: 'c'}


for x in d.values():
print(d[x])
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?

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

You might also like