# 310+ Problem Solving and Python Programming Solved MCQs

Chapters

Chapter: Algorithms
1.

## The word                         comes from the name of a Persian mathematician Abu Ja’far Mohammed ibn-i Musa al Khowarizmi.

A. flowchart
B. flow
C. algorithm
D. syntax
Explanation: the word algorithm comes from the name of a persian mathematician abu ja’far mohammed ibn-i musa al khowarizmi.
2.

## In computer science, algorithm refers to a special method usable by a computer for the solution to a problem.

A. true
B. false
Explanation: the statement is true. this word algorithm refers to a special method usable by a computer for the solution to a problem. the statement of the problem specifies in general terms the desired input/output relationship.
3.

## This characteristic often draws the line between what is feasible and what is impossible.

A. performance
B. system evaluation
C. modularity
D. reliability
Explanation: algorithms help us to understand scalability. performance often draws the line between what is feasible and what is impossible.
4.

## The time that depends on the input: an already sorted sequence that is easier to sort.

A. process
B. evaluation
C. running
D. input
Explanation: the running time depends on the input: an already sorted sequence is easier to sort. the running time is given by the size of the input, since short sequences are easier to sort than the longer ones. generally, we seek upper bounds on the running time, because it is reliable.
5.

## When an algorithm is written in the form of a programming language, it becomes a

A. flowchart
B. program
C. pseudo code
D. syntax
Explanation: an algorithm becomes a program when it is written in the form of a programming language. thus, any program is an algorithm.
6.

## Any algorithm is a program.

A. true
B. false
Explanation: the statement is false. an algorithm is represented in the form of a programming language is called a program. any program is an algorithm but the reverse is not true.
7.

## A system wherein items are added from one and removed from the other end.

A. stack
B. queue
D. array
Explanation: in a queue, the items are inserted from the rear end and deleted from the front end.
8.

## Another name for 1-D arrays.

A. linear arrays
B. lists
C. horizontal array
D. vertical array
Explanation: linear arrays are the 1- dimensional arrays wherein only one row is present and the items are inserted.
9.

## A data structure that follows the FIFO principle.

A. queue
B. ll
C. stack
D. union
Explanation: the answer is queue. a queue follows the fifo principle. fifo stands for first in first out.
Chapter: Flow Charts
10.

## The symbol denotes

A. i/o
B. flow
C. terminal
D. decision
Explanation: the symbol denotes a terminal. it is used for indication of start and stop nodes of a program.
11.

## In computer science, algorithm refers to a pictorial representation of a flowchart.

A. true
B. false
Explanation: the statement is false. the correct statement would be: in computer science, flowchart refers to a pictorial representation of an algorithm.
12.

## The process of drawing a flowchart for an algorithm is called

A. performance
B. evaluation
C. algorithmic representation
D. flowcharting
Explanation: it is called as flowcharting. a flowchart is nothing but a pictorial representation of an algorithm.
13.

## Actual instructions in flowcharting are represented in

A. circles
B. boxes
C. arrows
D. lines
Explanation: the actual instructions are written in boxes. boxes are connected by using arrows to indicate the exact flow of a flowchart and the order in which they are to be executed.
14.

## The following box denotes?

A. decision
B. initiation
C. initialization
D. i/o
Explanation: a diamond shape box denotes the decision making statements. it jumps to a truth value or a false value.
15.

## A box that can represent two different conditions.

A. rectangle
B. diamond
C. circle
D. parallelogram
Explanation: a diamond shape box denotes either a truth value or a false value. it jumps onto two different statements following it via flow lines.
16.

## There should be certain set standards on the amount of details that should be provided in a flowchart.

A. true
B. false
Explanation: the statement is false. there should be no set standards on the amount of details that should be provided in a flowchart.
17.

## A detailed flowchart is called

A. stack
B. macro
C. micro
D. union
Explanation: a detailed flowchart or a flowchart with more details is called as micro flowchart. it represents all the components of the algorithm that is followed.
18.

## Which of the following is not an advantage of a flowchart?

A. better communication
B. efficient coding
C. systematic testing
D. improper documentation
Explanation: flowcharts provide a proper documentation. it also provides systematic debugging.
19.

## A flowchart that outlines the main segments of a program.

A. queue
B. macro
C. micro
D. union
Explanation: the answer is macro flowchart. a macro flowchart outlines the important components of a program. it therefore shows fewer details.
Chapter: Designing Flowcharts
20.

## A                              is diagram that depicts the flow of a program.

A. algorithm
B. hash table
C. graph
D. flowchart
Explanation: a flowchart is a diagram that helps us determine the flow of the program. other options are irrelevant.
21.

## Terminals are represented by diagonals in a flowchart.

A. true
B. false
Explanation: the statement is false. terminals are represented by rounded rectangles. they indicate the starting or ending point in a flowchart.
22.

## The operation represented by parallelograms.

A. input/output
B. assignment
C. comparison
D. conditions
Explanation: the input/output operations are represented by parallelograms. they generally are used to display messages during input and output part of a program.
23.

## Which of the following is not a flowchart structure?

A. process
B. sequence
C. repetition
D. case
Explanation: there are basically four flowcharting structures:
24.

## The action performed by a                         structure must eventually cause the loop to terminate.

A. sequence
B. case
C. repetition
D. process
Explanation: the action performed by a repetition structure must eventually cause the loop to terminate. otherwise, an infinite loop is created.
25.

## The following symbol denotes:

A. module
B. terminal
C. process
D. i/o operation
Explanation: this symbol is that of a module. the terminal is denoted by a rounded rectangle. i/o operation by a parallelogram and process by a rectangle.
26.

## What type of structure is this?

A. sequence
B. case
C. repetition
D. process
Explanation: this is a repetition structure. the action performed by a repetition structure must eventually cause the loop to terminate. otherwise, an infinite loop is created.
27.

## A                is a connector showing the relationship between the representative shapes.

A. line
B. arrow
C. process
D. box
Explanation: arrows are the connectors that show the relationship between different
28.

## The following box denotes?

A. decision
B. input/output
C. process
D. module
Explanation: the answer is decision. conditions are given in this box and then the result is checked accordingly if the condition is true or false.
Chapter: Pseudo Code
29.

## Capitalize initial keyword – This is a rule while writing a pseudo code.

A. true
B. false
Explanation: the statement is true. it is an important rule to capitalize the initial keyword while writing a pseudo code.
30.

## is used to show hierarchy in a pseudo code.

A. indentation
B. curly braces
C. round brackets
D. semicolon
Explanation: each design structure uses a particular indentation pattern.
31.

## The statement that tells the computer to get a value from an input device and store it in a memory location.

B. write
D. write
Explanation: the read statement is used to take the input. read being a keyword should be in capital letters.
32.

## begins with lower case letters.

A. keywords
B. variables
C. tokens
D. functions
Explanation: variables begin with a lowercase. they contain no spaces. they also involve the consistent use of names.
33.

## Another notation for exponentiation.

A. *
B. **
C. ***
D. *^
Explanation: double asterisk sign is also used for exponentiation. the general notation is ^ sign.
34.

## A symbol used for grouping.

A. ()
B. {}
C. []
D. ” ”
Explanation: parenthesis is used for grouping while working with fields. there are other symbols like *, +, -, **, etc.
35.

## A statement used to close the IF block.

A. else
B. elseif
C. end
D. endif
Explanation: the answer is endif. it is used
Chapter: Variables
36.

## Is Python case sensitive when dealing with identifiers?

A. yes
B. no
C. machine dependent
D. none of the mentioned
Explanation: case is always significant.
37.

## 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. none of the mentioned
Explanation: identifiers can be of any length.
38.

## Which of the following is invalid?

A. _a = 1
B.     a = 1
C.     str     = 1
D. none of the mentioned
Answer» D. none of the mentioned
Explanation: all the statements will execute successfully but at the cost of reduced readability.
39.

A. my_string_1
B. 1st_string
C. foo
D. _
40.

## 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. they are used to indicate a private variables of a class
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.
41.

## Which of the following is not a keyword?

A. eval
B. assert
C. nonlocal
D. pass
Explanation: eval can be used as a variable.
42.

## All keywords in Python are in

A. lower case
B. upper case
C. capitalized
D. none of the mentioned
Answer» D. none of the mentioned
Explanation: true, false and none are capitalized while the others are in lower case.
43.

## 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. a b c = 1000 2000 3000
Explanation: spaces are not allowed in variable names.
44.

## Which of the following cannot be a variable?

A. __init__
B. in
C. it
D. on
Explanation: in is a keyword.
Chapter: Operators
45.

## Which is the correct operator for power(xy)?

A. x^y
B. x**y
C. x^^y
D. none of the mentioned
Explanation: in python, power operator is x**y i.e. 2**3=8.
46.

## Which one of these is floor division?

A. /
B. //
C. %
D. none of the mentioned
Explanation: when both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. this is floor division. for ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2. to get the 2.5 answer, use floor division.
47.

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

A. 7
B. 1
C. 0
D. 5
Explanation: modulus operator gives the remainder. so, 22%3 gives the remainder, that is, 1.
48.

## Mathematical operations can be performed on a string.

A. true
B. false
Explanation: you can’t perform mathematical operation on string even if the string is in the form: ‘1234…’.
49.

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

A. 27
B. 9
C. 3
D. 1
Explanation: first this expression will solve 1**3 because exponential has higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. final answer is 3.
50.

## Which one of the following has the same precedence level?

C. multiplication, division, addition and subtraction
Explanation: “addition and subtraction” are at the same precedence level. similarly, “multiplication and division” are at the same precedence level. however, multiplication and division operators are at a higher precedence level than addition and subtraction operators.
51.

## Which one of the following has the highest precedence in the expression?

A. exponential
C. multiplication
D. parentheses
Explanation: just remember: pemdas, that is, parenthesis, exponentiation, division, multiplication, addition, subtraction. note that the precedence order of division and multiplication is the same. likewise, the order of addition and subtraction is also the same.
Chapter: Data Types
52.

## Which of these in not a core data type?

A. lists
B. dictionary
C. tuples
D. class
Explanation: class is a user defined data type.
53.

## 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
Explanation: python shell throws a nonetype object back.
54.

## 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)
Explanation: execute help(round) in the shell to get details of the parameters that are passed into the round function.
55.

## What is the return type of function id?

A. int
B. float
C. bool
D. dict
Explanation: execute help(id) to find out details in python shell.id returns a integer value that is unique.
56.

## 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
Answer» D. all of the mentioned
Explanation: // is integer operation in python
57.

## 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
B. cannot perform mathematical operation on strings
C. hello2
D. hello2hello2
Explanation: python codes have to be indented properly.
58.

## What data type is the object below? L = [1, 23, 'hello', 1]

A. list
B. dictionary
C. array
D. tuple
Explanation: list data type can store any
59.

## 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
Explanation: dictionary stores values in terms of keys and values.
60.

## 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”’
Explanation: carefully look at the colons.
61.

## 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
Explanation: cause a decimal value of 0 to appear as output.
62.

## What is the return value of trunc()?

A. int
B. bool
C. float
D. none
Explanation: execute help(math.trunc) to get details.
Chapter: Numeric Types (Int,Float)
63.

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

A. true
B. false
C. machine dependent
D. error
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.
64.

## 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. k = 2 + 3l
Explanation: l (or l) stands for long.
65.

## What is the type of inf?

A. boolean
B. integer
C. float
D. complex
Explanation: infinity is a special case of floating point numbers. it can be obtained by float(‘inf’).
66.

## What does ~4 evaluate to?

A. -5
B. -4
C. -3
D. +3
Explanation: ~x is equivalent to -(x+1).
67.

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

A. 1
B. 0
C. true
D. false
Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y.
68.

## Which of the following is incorrect?

A. float(‘inf’)
B. float(‘nan’)
C. float(’56’+’78’)
D. float(’12+34′)
Explanation: ‘+’ cannot be converted to a float.
69.

## 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. value depends on python version
Explanation: the behavior of the round()
70.

## What does 3 ^ 4 evaluate to?

A. 81
B. 12
C. 0.75
D. 7
Explanation: ^ is the binary xor operator.
Chapter: Precedence of Operators
71.

## The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.

A. true
B. false
Explanation: although the presence of parenthesis does affect the order of precedence, in the case shown above, it is not making a difference. the result of both of these expressions is 1.333333333. hence the statement is true.
72.

## What will be the value of the following Python expression? 4 + 3 % 5

A. 4
B. 7
C. 2
D. 0
Explanation: the order of precedence is: %,+. Hence the expression above, on
simplification results in 4 + 3 = 7.
Hence the result is 7.
73.

## Which of the following operators has its associativity from right to left?

A. +
B. //
C. %
D. **
Explanation: all of the operators shown above have associativity from left to right, except exponentiation operator (**) which has its associativity from right to left.
74.

## 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
Explanation: The expression shown above is
an example of explicit conversion. It is
evaluated as int(43.55+1) = int(44.55) = 44.
Hence the result of this expression is 44.
75.

## 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)
Explanation: the result of the expression shown above is (6.0, 16.0). this is because the result is automatically rounded off to one decimal place.
76.

## Which of the following is the truncation division operator?

A. /
B. %
C. //
Explanation: // is the operator for truncation division. it is called so because it returns only the integer part of the quotient, truncating the decimal part. for example: 20//3 = 6.
77.

## 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
Explanation: Expression 1 is evaluated as:
2**9, which is equal to 512. Expression 2 is
evaluated as 8**2, which is equal to 64. The
last expression is evaluated as 2**(3**2).
This is because the associativity of **
operator is from right to left. Hence the result
of the third expression is 512.
78.

## 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)
Explanation: the above expressions are evaluated as: 2/2, 8/2, which is equal to (1.0, 4.0).
79.

## 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
Explanation: The expression shown above is
evaluated as: 2+9*(36-8)/10, which simplifies
to give 2+9*(2.8), which is equal to
2+25.2 =27.2.
Hence the result of this expression is 27.2.
80.

## 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)
Explanation: the expressions are evaluated as: 4%3 and 6//2 respectively. this results in the answer (1,3). this is because the associativity of both of the expressions shown above is left to right.
81.

## 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
Explanation: the above expression is an example of explicit conversion. it is evaluated as: float(4+int(2.39)%2) = float(4+2%2) = float(4+0) = 4.0. hence the result of this expression is 4.0.
82.

## What will be the value of the following Python expression? 4+2**5//10

A. 3
B. 7
C. 77
D. 0
Explanation: The order of precedence is: **,
//, +. The expression 4+2**5//10 is evaluated
as 4+32//10, which is equal to 4+3 = 7. Hence
the result of the expression shown above is 7.
83.

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

A. true
B. false
Explanation: the value of the expression (2**2)**3 = 4**3 = 64. when the expression 2**2**3 is evaluated in python, we get the result as 256, because this expression is evaluated as 2**(2**3). this is because the associativity of exponentiation operator (**) is from right to left and not from left to right.
Chapter: Bitwise Operator
84.

## What will be the output of the following Python expression? int(1011)?

A. 1011
B. 11
C. 13
D. 1101
Explanation: the result of the expression shown will be 1011. this is because we have not specified the base in this expression.
85.

## Which of the following expressions results in an error?

A. int(1011)
B. int(‘1011’,23)
C. int(1011,2)
D. int(‘1011’)
Explanation: the expression int(1011,2) results in an error. had we written this expression as int(‘1011’,2), then there would not be an error.
86.

## Which of the following represents the bitwise XOR operator?

A. &
B. ^
D. !
Explanation: the ^ operator represent bitwise xor operation. &: bitwise and,
87.

## What is the value of the following Python expression? bin(0x8)

A. ‘0bx1000’
B. 8
C. 1000
D. ‘0b1000’
Explanation: the prefix 0x specifies that the value is hexadecimal in nature. when we convert this hexadecimal value to binary form, we get the result as: ‘0b1000’.
88.

## What will be the output of the following Python expression? 0x35 | 0x75

A. 115
B. 116
C. 117
D. 118
Explanation: the binary value of 0x35 is 110101 and that of 0x75 is 1110101. on or- ing these two values we get the output as: 1110101, which is equal to 117. hence the result of the above expression is 117.
89.

## It is not possible for the two’s complement value to be equal to the original value in any case.

A. true
B. false
Explanation: in most cases the value of two’s
90.

## 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
Explanation: bitwise xor gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
91.

## What will be the output of the following Python expression? 4^12

A. 2
B. 4
C. 8
D. 12
Explanation: ^ is the xor operator. the binary form of 4 is 0100 and that of 12 is 1100. therefore, 0100^1100 is 1000, which is equal to 8.
More MCQs
92.

## 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
Explanation: let us consider an example wherein a=2. the binary form of 2 is 0010. when we left shift this value by 2, we get 1000, the value of which is 8. hence if we want to multiply a given number ‘a’ by 4, we can use the expression: a<<2.
93.

## R operator. Hence the output of the code shown above is: 20 10.

A. 1011011
B. 11010100
C. 11101011
D. 10110011
Explanation: the binary form of -44 is 00101100. the one’s complement of this value is 11010011. on adding one to this we get: 11010100 (two’s complement).
94.

## 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
Explanation: the expression not(10<20) returns false. the expression not(10>30) returns true. the and operation between false and true returns false. hence the output is false.
95.

## What will be the output of the following Python code? for i in range(0): print(i)

A. 0
B. no output
C. error
D. none of the mentioned
Explanation: range(0) is empty.
96.

## 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
Explanation: object of type float cannot be interpreted as an integer.
97.

## 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
Explanation: range(int(2.0)) is the same as range(2).
98.

## What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[0] in a: print(a[0])

A. 0 1 2 3
B. 0 1 2 2
C. 3 3 3 3
D. error
Answer» A. 0 1 2 3
Explanation: the value of a[0] changes in each iteration. since the first value that it takes is itself, there is no visible error in the current example.
99.

## What will be the output of the following Python statement? >>>"a"+"bc"

A. a
B. bc
C. bca
D. abc
Explanation: + operator is concatenation operator.
100.

A. a
B. ab
C. cd
D. dc