You are on page 1of 34

Dr. D. Y.

Patil Institute of Technology, Pimpri, Pune -18


Department of First Year Engineering
Sub: Programming and Problem Solving
Unit - 1 MCQ

Q. No. Question Option A Option B Option C Option D Ans.


1 Which of the following is the program design tool? Sequential Flowchart Pseudocode Both B & C D
Easy testing &
2 Flowcharts and Algorithms are used for ____ Better Programmming Efficient coding All D
debugging
3 An algorithm represented in the form of programming language is ____ Flowchart Pseudocode Program None C
4 Which of the following is pictorial representation of algorithm? Pseudo code Program Flowchart Algorithm C
5 Pseudo code is also known as Program Design Language Hardware Language Software Language Algorithm A
6 What flowchart symbol does parallelogram represent? Input/Output Start/End Decision Process A
7 The ______ symbol is always first and last symbol in the flowchart. Rectangle Parallelogram Terminal Symbols Diamond C
8 _______ is a form of structured english that describes algorithms. Flowchart Pseudocode Algorithm None B
9 ______ is used to express algorithms and as a mode of human communication. Flowchart Pseudocode Algorithm None A
10 Algorithms should be Precise Unambiguous Clear All of these D
To check whether a given number is even or odd, you will use which control
11 Sequence Decision Repetition All of these B
structure?
12 Which of the following is graphical or symbolic representation of a process? Algorithm Flowchart Pseudocode Program B
13 In a flowchart which a activity is represented using rectangle? Terminal Decision Process Input/Output C
14 Which of the following details are omitted in pseudocodes? Variable declaration System specific code memory allocations All of these D
15 Identify the words which best describe python. Interpreted relaiable Simple All of these D
16 Select the integer literal. 10.345 9 '9' "9" B
17 Which of these will not be stored as a float? 23 56/59 15 ABC D
18 Which operator gives remainder after division? / // % * C
Python allows you to specify unicode text by prefixing the string with which
19 U R S A A
character?
What is the output of this code? print"print print
20 print'''print hello''' An error message print print hello' A
>>>print("print'''print hello''''') hello"
21 Which of the following is a valid string literal? "Computer" 'Computer' '''Computer''' All of these D
22 Which line of code produces an error? "one" + "2" '5' + 6 3+4 "7" + 'eight' B
>>>spam = "eggs"
23 Spamspamspam eggseggseggs "spamspamspam" spam*3 B
>>>print(spam*3)
What is the output of this code?
24 "70" "3040" 3040 ("30" + "40") C
>>>int("30" + "40")
What is the output of this code?
123123123.0 ,after
25 >>>float("123"*int(input("Enter a number"))) "123123123" "369.0" 369 C
decimal 0 will be there
Enter a number: 3
26 Identify correct variable name. this_is var=7 123abc=10.22 ThisBook = "Python" %name = "xyz" C
27 A variable can be removed using which keyword. remove clear del delete C
To specify more than one statements in a single line, use a ___ to separate the
28 , ; : / B
statements.
29 The input() function takes user's input as a integer float string character C
30 Comment start with which symbol? " // # * C
31 Bitwise operator can be applied on which datatype? integer float string list A
32 Which operator treats opearand as a sequence of bits? Relational Arithmetic Bitwise Logical C
33 Which operator is also known as string repetition operator? + * & ^ B
34 If, x=5; y=_; and print(x+y) gives 12, then y is 7 = 7 "7" A
35 Which of the following results in True? >>>9=9 and 1==l >>>3==5 and 7==3 >>>7!=1 and 5==5 >>4<1 or 1>6 C
What is the output of the following code?
x=6
66 36 66 36
36 y=2 D
0 0 3 3
print(x ** y)
print(x // y)
37 Which of the following operators has the highest precedence? not and * + C
What is the output of the following code
x = 100
38 TRUE 100 FALSE 50 D
y = 50
print(x and y)
39 >>>print(format(56.78901,'03f')) 56.789 5.6789 0.56789 56789 A
40 Identify the expression that may result in arithmetic overflow. a*b a**b a/b a+b B
41 Which of these is a valid variable name in python? This is a variable This_Is_A_VARIABLE This-is-a-variable ^var B
42 Which of the following results is True? >>> 9=9 or 1==1 >>> 3==4 or 7==7 >>> 7!=1 or 5==5 >>> 4<1 or 1>6 C
43 Identify the correct arithmetic expression in python. 11(12+13) (5*6)(7+8) 4*(3-2) 5***3 C
Set of Algorithms that
Set of Language that is Set of Instructions that
Operations that is arranged in is arranged in
arranged in sequence to is arranged in sequence
sequence to guide a computer sequence to guide a
44 A Program is the guide a computer to find to guide a computer to C
to find solution for the given computer to find
solution for the given find solution for the
problem solution for the given
problem given problem
problem
45 Computer operate on ____based on __ Data,Instructions Data ,Algoritm Instructions,Data Algorithm ,FlowChat A
46 The Speed of Computer is expressed in ___or _________ sec,milli sec nano sec,pico sec micro sec,milli sec nano sec,micro sec B
47 Raw facts or figures are called data algorithm flowchart design A
48 ____ and ___ are examples of first generation computing devices Super,ENIAC ENIAC,Macro ENIAC,EDVAC SUPER,EDVAC C
49 Literals of the form a+bi are called String Integer Float Complex Numbers D
50 123.45E-9 is equal to 123.45* 10+9 123.45* 10 123.45* 10-9 123.45* 10*9 C
51 Following coverts an integer to floating point number Explicit Conversion Implicit Conversion Exclusive Conversion Inclusive Conversion B
52 The -------operator returns quotient after division / // ** ^ B
53 following are reserved memory locations that stores values Variables Datatype Literal Keywords A
54 To find x raise to y,which operator you will use ** ^ % >> A
55 ____________is group of characters int list float String D
56 __________ is a standard way of writing international text String Unicode Text UTF-8 B
57 __________are part parts of your computers memory where information is stored Value Data Variables Address C
58 R "Hi" indicates that the string a _______String Raw Basic Literal Keywords A
Letters,operators Digits,operators keywors,special
59 Variables names can contain only______,_______and______ Letters,numbers ,underscore A
,underscore ,underscore symbols ,underscore
60 _______of a variable gives an indication of what type of value will be stored in it. Address DataType name id B
61 Python refers to everything as an ____including numbers and strings Class Keyword Object Literal C
62 A variable is automatically declared when ________ A value is assigned to it A value is display A value is removed A value is searched A
63 A program in python is strored with extension__ .python .pyth .p .py D
64 To print "hello",you will write -----------("hello") input() print type int B
65 If (______7*-3)+9=30,Fill the missing character + =' +' *' __ D
What should be written in the blank to genereate ZeroDivisionError in case of
66 2 8 9 4 B
(25+36) / (-8+___________)
67 If(2+______)**2=25 2 4 3 1 C
68 To prompt the user for an input ,__________function is used input() type() int() get() A
69 To print "Python is fun",we use print("python"+'__________+"_______) is',fun" is,fun "is,fun" is','fun' A
70 A Statement block is formed by the level of__________. brackets Indentation function list B
71 __________operands act on single operands. binary Singular Unary ternary C
72 __________operator performs logical negation on each bit of the operand Bitwise NOT Bitwise and Bitwise or ^ A
If expressions on both the sides of the logical operator & are true ,then the whole
73 FALSE TRUE CANT SAY none B
expression is________
74 _________can change the order in which an operator is applied Arithmetic Exponent division Parenthesis D
Fill in the blanks to declare a variable ,add multiply 2 to it,and print its value.
75 num,+ x,num *,num '+',num C
>>>num=12; x____________=2; print______________.
76 Boolean values in python are _______and __________ True,False true,false TRUE,FALSE true,FALSE A
77 >>>70!=80 gives output as _____________ FALSE 0 TRUE 1 C
78 89%0= 0 division by 0 Error 89 1 B
79 Python uses English-like words. TRUE FALSE A
80 Python is a proprietary programming language. TRUE FALSE B
81 You can call functions of the operating system from a program written in Python . TRUE FALSE A
82 You can makes games in python TRUE FALSE A
83 A good python program must use any specific feature. TRUE FALSE B
It is possible to code a part of your program in c or c++ and then use them in a
84 TRUE FALSE A
python program
85 code written in python is difficult to maintain. TRUE FALSE B
86 An object that is currently being used is eligible for garbage collection. TRUE FALSE B
87 Programmer should explicilty delete an unused object TRUE FALSE A
88 Python has been derived from C. TRUE FALSE A
89 Python supports only object oriented programming paradigm. TRUE FALSE B
90 In python, integers can be specified in octal as well as hexadecimal number system. TRUE FALSE A
91 All spaces and tabs within a string are preserved in qutoes. TRUE FALSE A
92 Each variable has a unique name. TRUE FALSE A
93 You can not multiply a string with a floating point number. TRUE FALSE A
94 You can not use single qutoes & double qutoes in a string within triple qutoes. TRUE FALSE B
95 You can print a string without using print function. TRUE FALSE A
96 char is a valid data type in python . TRUE FALSE B
If you want to specify a string that should not handle any escape sequences, then
97 TRUE FALSE B
you need to specify it as a unicode string.
98 Python is a case-Insensitive langauage TRUE FALSE B
99 Variable names can start with numbers. TRUE FALSE B
100 A variable can assign a value only once. TRUE FALSE B
101 Python variable do not have specific types. TRUE FALSE A
102 Keywords cannot be used for naming identifiers. TRUE FALSE A
103 Relational operators are used to compare the values on its either sides. TRUE FALSE A
104 In-place operators can be applied on strings. TRUE FALSE A
105 You can add as well as multiply two strings. TRUE FALSE B
Find Output of the following:
Q. No. Question Correct Answer
The following statement will produce _______ lines of output.
106 4
print('Good\n Morning \n World\n ---Bye')
108 >>>250+130-70 310
109 >>>(32+5.2-3)*10 342
110 >>>100%(45//2) 12
111 >>> 'python is an interesting language' 'python is an interesting language'
>>> '''Hi ... \n Hi …
113
How are you?''' How are you?
Python
114 >>>print(“Python \n is \n Fun!!!”) is
Fun!!!
115 >>>print(“Great !!!!”*3) Great !!!! Great !!!! Great !!!!
116 >>>4*'2' '2222'
117 >>>print(3*'7') 777
>>>x = 10
118 >>>x *= 3 30
>>>print(x)
>>>x = “Hello, ”
119 >>>x+ = “World!!!” Hello, World!!!
>>>print(x)
Days are : Mon Tue Wed Thu Fri Sat Sun
Months are: Jan
days = "Mon Tue Wed Thu Fri Sat Sun" Feb
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug" Mar
print("Days are : "+ days) Apr
120 print("Months are: "+ months) May
print(""" There's a new dream today. I'll tell you some other day. Jun
Come on, let's enjoy. """) Jul
Aug
There's a new dream today. I'll tell you some other day. Come on, let's enjoy.

121 # print(1234) Nothing is printed


What is the output of this code?
>>>num1 = 2
>>>num2 = 3
>>>del num1
122 20
>>>num2 = 4
>>>num1 = 5
>>>print(num1 * num2)

>>> num1 = "7"


>>> num1 += "10"
123 >>> num2 = int(num1) + 3 713.0
>>> print(float(num2))

124 >>> word = input("Enter a word :") Enter a word: Hello


>>> num1 = 9
>>> num2 = num1 + 5
125 144
>>> num2 = int(str(num2) + "4")
>>> print(num2)
126 abs(10-20) 10
127 print(abs(10-20) * 3) 30
Dr. D. Y. Patil Institute of Technology, Pimpri, Pune -18
Department of First Year Engineering
Sub: Programming and Problem Solving
Unit - 2 MCQ

Q. No. Question Option A Option B Option C Option D Ans.


Statements within
1 Which part of if statement should be indented? First statement All the statements None of these C
the if block
How many numbers will be printed?
i=5
2 while i>=0: 5 6 4 0 B
print(i)
i=i-1
Which statement ends the current iteration of the loop and continues with the next
3 break continue skip pass B
one?
4 Which of the following is placed after the if condition? ; . : , C
5 Python uses _________ to form a block of code. Curly brackets Indentation Colon None of the above B
6 for loop in python is Entry control loop Exit control loop Selection statement None of the above A
7 Which statement indicates a NOP? pass break continue jump A
It will stop You will have to There would be no
8 What would happen if we replace the break statement in the code with a 'continue'? It would run forever B
executiong press Ctrl+C change
9 if -3 will evaluate to true TRUE FALSE A
Directs the order of Dictates what
Defines program-
execution of the happens before the
10 In a Python program, a control structure: specific data None of the above B
statements in the program starts and
structures
program after it terminates
What is the output of the following loop
for l in 'Jhon':
11 if l == 'o': J, h, n, J, h, o, n, J, h, J, B
pass
print(l, end=", ")
What is the final value of x
x=0 None of the above,
12 while (x < 200): 201 199 this is an infinite 200 D
x+=2 loop
print(x)
What will be the output of the following Python code?
for i in range(0,2,-1):
13 Hello Hello Hello No Output Error C
print("Hello")
14 Which of the following is a valid for loop in Python? for(i=0; i < n; i++) for i in range(0,5): for i in range(0,5) for i in range(5) B
Which of the following sequences would be generated bt the given line of code?
15 5 4 3 2 1 0 -1 543210 531 None of the above C
range (5, 0, -2)
16 A while loop in Python is used for what type of iteration? indefinite discriminant definite indeterminate A
How many lines will be printed by this code?
17 while False: 0 1 10 countless A
print("Hi")
When break When loop
Else statement is
18 When does the else statement written after loop executes? statement is condition becomes None of the above B
always executed
executed in the loop false
Find the output:
num=70
if num == 50:
print("50") 70
elif num == 10: Number is not 70
Number is not
19 print("10") 50,10 or 70 Number is not 70 B
50,10 or 70
elif num == 70: Number is not 50,10 or 70
print("70") 50,10 or 70
else:
print("Number is not 50,10 or 70")
print("Number is not 50,10 or 70")
What is the output of the following if statement
a, b = 12, 5
if a + b:
20 TRUE FALSE Both None A
print('True')
else:
print('False')
Given the nested if-else structure below, what will be the value of x after code
execution completes
x=0
a=0
b = -5
if a > 0:
if b < 0:
21 x=x+5 2 0 3 4 A
elif a > 5:
x=x+4
else:
x=x+3
else:
x=x+2
print(x)
22 What keyword would you use to add an alternative condition to an if statement? else if elseif elif None of the above C
________ statements are used to repeatedly execute one or more statements in a
23 Sequencial Selection Iterative Jump C
block.
We use for loop
Python’s for loop
else clause of for else clause of for when we want to
used to iterates over
loop is executed loop is executed perform a task
24 Select which is true for for loop the items of list, B
when the loop when the loop indefinitely until a
tuple, dictionary,
terminates naturally terminates abruptly particular condition
set, or string
is met
25 Which statement will check if a is equal to b? if a = b: if a == b: if a === c: if a == b B
26 Which one of the following is a valid Python if statement ? if a>=2 : if (a >= 2) if (a => 22) if a >= 22 A
Python has switch
27 Does python have switch case statement? TRUE FALSE statement but we None of the above B
can not use it.
>>> colors = ["mon", "tue", "wed", "thur"]
28 >>> colors[2] 'mon' 'tue' 'wed' 'thur' C
What is the output of colors[2] expression?
if/else not used in
29 Can we write if/else into one line in python? Yes No None of the above A
python
When one doesn't
When one wants to know in advance
When taking change the order of When a statement how many iterations
30 When should a 'while' loop be used? D
guesses from a user execution of evaluates to 'false' would be needed to
statements perform a repeated
operation
What does the following code print to the console?
31 ice cream is tasty! 2 Error None A
if 2 == 2:
print("ice cream is tasty!")
What does the following code print to the console?

name = "maria"
if name == "melissa":
32 print("usa") melissa mary colombia ireland C
elif name == "mary":
print("ireland")
else:
print("colombia")
33 Which of the following is not used as loop in Python? for loop while loop do-while loop None of the above C
What will be the output of the following Python code?
i=5
while True:
34 if i%3 == 0: 5 7 9 11 13 … 5 7 579 Error B
break
print(i)
i += 2
What will be the output of following code?
2, 1, 0, -1, -2, -3, -4,
35 2, 1, 0 2, 1, 0, -1, -2 2, 1, 0, -1, -2, -3 C
for num in range(2,-3,-1): -5
print(num, end=", ")
What will be the output of the following Python code?
36 d = {"john":4, "harry":45} 4 45 “john” “harry” A
print(d["john"])
What does the following code print to the console?

if False:
print("Nissan")
elif True:
37 Nissan Ford BMW Audi B
print("Ford")
elif True:
print("BMW")
else:
print("Audi")
Keyword
No loop can be used "continue" is used Keyword "break"
Loops should be
to iterate through to continue with the can be used to bring
38 Which of the following is True regarding loops in Python? ended with D
the elements of remaining control out of the
keyword "end".
strings. statements inside current loop.
the loop.
What is the output of the following nested loop
for num in range(10, 14): 10
10
for i in range(2, num): 11 10
39 11 10 A
if num%i == 1: 12 11
12
print(num) 13
break
40 while(0), how many times the loop will run? 0 1 3 Infinite A
X=100
Y=200
41 ---x>y---print(“In if”) if,:,else: else, if all the of above None of the above A
-------prin(“In else”)

42 ----------is a short form of “else if ” statement if else elif if__else else__if B


Fill the blanks to print Welcome on the screen
x=15
43 printf Print or,print None of the above C
y=500
if x>100----y>100:----("Welcome")
44 >>>not 1==1 gives the answer------- TRUE FALSE B
i=1
while i>0:
45 while loop Finite loop Infinite Loop For loop C
print("loop")
The above loop is an example of------
Fill the blanks to create a loop that increments the value of x by 2 and prints the
even values from 0-100
x=0
46 ----x <=----- while,100;,print 100,print while, print All of the above A
----(x)
x +=2

47 Python uses --------------to form a block of code break comments Selection statement indentation D
A series of if-elif statements have a final----------block, which is executed if none
48 nested if else elif nested if , if, if else D
of the if or elif expressions is True
49 Python assumes any non-zero and non-null values as--------- TRUE FALSE A
50 --------statements are used to repeatedly execute one or more statements in a block First statement All the statements Iterative None of these C
51 If the condition in the while loop never becomes False, then it will result in an----- Syntax Error Infinite loop executing bug B
-----loop can be used when the number of times the statements in loop has to be
52 break continue while pass C
executed is not known in advance
53 -------loop is called a definite loop ; . for , C
54 when a for loop is used, a --------of sequence is specified Curly brackets range Colon None of the above B
55 ----------is a built-in function that is used to iterate over a sequence of numbers Entry control loop Exit control loop Selection statement range( ) D
56 If your requirement is to have a counter-controlled loop, then choose----loop for break continue jump A
It will stop You will have to
57 To specify an empty body of a for loop,you will use------statement It would run forever pass D
executiong press Ctrl+C
Fill in the blanks to create a for loop that prints only the odd values in the range:-----
-I in range(0,20,):
58 print(-------) for,2*i+1 for 2+i for i+2*1 2*i A

Dictates what
Defines program-
happens before the
59 A--------statement contains other statements specific data compound None of the above B
program starts and
structures
after it terminates
60 --------begin with a keyword and end with a colon Headers For Loop While loop All of the above A
61 Indentation identifies a statement block TRUE FALSE A
62 You can not use logical operators in if statement condition TRUE FALSE B
63 Statement in if-else block should be properly aligned TRUE FALSE A
64 You can use floating point numbers for checking for equality in the test expression TRUE FALSE B
65 It is necessary that every if statement should have an else block TRUE FALSE B
66 elif and else blocks are optional TRUE FALSE A
While forming the condition expression ,we should use positive statements
67 TRUE FALSE A
rather than using compound negative statement
The while loop is used to repete one or more statements while a paricular
68 TRUE FALSE B
condition is False
If the control condition evaluates to False,then the statements enclosed in the loop
69 are TRUE FALSE A
never executed
Every alternate item of the sequence is assigned to the loop control variable one
70 TRUE FALSE B
after the other
71 The step argument in range () can be zero TRUE FALSE B
72 A sentinel controlled loop can be implemented using the for loop TRUE FALSE A
73 Loops can be nested to any desired level TRUE FALSE A
74 You can use break or continue statement outside loop TRUE FALSE B
75 pass is a null statement TRUE FALSE A
76 You can have the else statement associated with loop statement TRUE FALSE A
In a while loop ,if the body is executed n times then test expression is executed
77 TRUE FALSE A
n+1 times
The number of time the loop control variable is updated is equal to the number of
78 times TRUE FALSE A
loop iterates
79 In the while loop ,the loop control variable is initialized in the body of loop TRUE FALSE B
80 All if statements must contain eigther an else statement TRUE FALSE B
Which statement is used to terminate the execution of the nearest enclosing loop in
81 B
which it appears? pass break continue jump
The statement is used to stop the currrent iteration of the loop and continues with
82 C
the next one? pass break continue jump
while False:
83
print("Hello") Hello No output
84 Statement within a suite can be intended a different amount TRUE FALSE B
Find output:
years = 200
if (years == 100):
print( "Century")
elif (years == 75):
print ("Platinum Jublee")
elif (years == 50):
85 print ("Half Century") Nothing
elif (years == 25):
print("Silver Jublee")
elif(years == 10):
print("Decade")
else:
print ("Nothing")
num = 100
if num > 30:
print("30")
86 if num<50: 30
print("50")
if num==7:
print("70")
x=100
if x == 50:
87 print("Yeah") Try Again
else:
print("Try Again")
num = 100
if (num + 1) > 100:
if (num * 2) >= 200:
88 You win
print( "You win")
else:
print( "Try Again")
num = 70
if num == 50:
print( "50")
elif num == 10:
89 print( "10") 70
elif num == 70:
print( "70")
else:
print("Number is not 50, 10 or 70")
if(10 == 10) and (10+20>30):
print("Done")
90 Do It
else:
print("Do It")
91 >>> not 10>70 TRUE
if not True:
print("10")
elif not(10+10 == 30):
92 20
print("20")
else:
print("30")
if 10 + 30 == 60:
print("Best")
93 Worst
else:
print("Worst")
a = 10
b = 20
if not 10 + 10 == b or a == 40 and 70== 80:
94 No
print ("Yes")
elif a != b:
print("No")
i=1
while i<=6:
95 print(i, end = " ") 1 2 3 4 5 6 Done
i=i+1
print("Done")
i=0
while i<10:
i=i+1
if(i == 5): 1234
print("\n Continue") Continue
96 continue 6
if(i==7): Breaking Done
print("\n Breaking")
break
print( i, end = " ")
print( "\n Done")
for i in range(5):
97 hello! hello! hello! hello! hello!
print("hello!", end = " ")
for i in range(10): 2
98 if not i%2==0: 4
print(i+1) 6
Dr. D. Y. Patil Institute of Technology, Pimpri, Pune -18
Department of First Year Engineering
Sub: Programming and Problem Solving
Unit - 3 MCQ

Q. No. Question Option A Option B Option C Option D Ans.


def factorial ( n ) :
1 Yes No A
is this function header line correct
2 Text enclosed in ‘’’ ‘’’ or “”” “”” is called ………… Docstring Function Subheader String None of these A
Functions gives Simplicity in error Independent Execution time
3 Which of the following is not an advantage of functions D
modularity to programs correction development reduction
4 Return statement is used to return a value from a function TRUE FALSE A
Which of the following is not a builtin function
5 1.len(), 2. max(), 3. avg(), 4. min() ,5. fact(), 6. int() , 7. str() , 8. id() , 9. dict() ,10. str(), 11. 1,3 3,5 1,9,12 8,9,10 B
chr(), 12.ord()
A global variable can be
A global variable is Global variable
A global variable is modified in function by
6 What is false about global variable in python accessible in all overrides local variable D
declared in main redeclaring it with
functions with same name
global keyword
7 Variables types based on scope are Global , Local and nonlocal TRUE FALSE A
It is the time duration Local variable lifetime
Lifetime of local Variable lifetime is
between variable is from start of
8 Which of the following is true about lifetime of a variable variable is for the entire same for all types of A
creation and it is execution of a program
execution of a program variable
removed from memory upto end of execution.
9 lambda function is a function with single line expression anonymous function FALSE TRUE B
10 Which of the following is wrong about importing a module math for using functions. import math import math as M from math import sqrt import from math sqrt D
11 Which of the following a building module in python math random numpy functions D
A package is a hierarchical file directory structure that defines a single Python application
12 TRUE FALSE A
environment that consists of modules and subpackages and sub-subpackages…
13 Which of the following is not a type of function Builtin Usef defined Library functions Mixed functions D
Default arguments Keyword and variable
14 Which of the following are argument types in python functions Required arguments All of these D
length
Arguments are actual In default argument In keyword arguments
and formal formal parameters in formal parameters are
15 Which of the following is correct about arguments All of these D
declaration header are assigned values in call
assigned values statement
What following function computes
def fun1( x ):
p=1
16 Product of x+1 values Product of x- 1 values x factorial None of these C
for i in range ( 2 , x+1) :
p= p*i
return(p)
What is the output of the following program :
y=8
17 48 14 64 84 A
z = lambda x : x * y
print (z(6) )
If there are more lines in
The following lines in
The doc string line the documentation
docstring should be one
should begin with a string, the second line
The first line should be or more paragraphs
18 Which of the following is not a rule to write a docstring small letter and end with should be blank, A
a short description. describing the object’s
a comma. visually separating the
calling conventions,
summary from the rest
its side effects.
of the description.

19 Variable length argument is useful when exact number of arguments passed are not known. FALSE TRUE B
20 One function can be written inside another function TRUE FALSE A
A module is a file consisting of Python code. A module can define functions, classes and
21 FALSE TRUE B
variables.
22 User defined functions are created by using ___ keyword. return def import create B
Function definition
23 ____ consists of a function header followed by function body. Function call Package Program A

Function definition
24 _____ is used to uniquely identify the function. Function call Function name Program A
What is the output of the following segment
25 A a 65 Error A
print ( chr ( ord ( ‘A’) ) )
function definition
26 After the called function is executed, the control is returned back to the ____ lambda function Module Calling function D

27 Before calling a function, you must ___ it. call define return pass parameter B
28 Large programs usually follow WET principle. TRUE FALSE B
29 DRY principle makes the code __ Reusable Loop forever Bad and repetitive Complex A
def function_name( function_name( function_name(arguman
30 Which is the correct syntax for function call. function_name D
argumnts) arguments) call ts )
A function is a block of organised and reusable program code that performs multiple, related, multiple, related, well single, specific, well
31 single, small, dependent C
a ___ , _____ and _____ task. dependent defined defined
def person(name,
32 Which of the following function header is example of Default Argument? def person(name, age): def car(model, cost): def sum(a, *tup): B
age=18):
Number of arguments
in the function call
The arguments are
should exactly match One or more arguments
33 What are the characteristics of required arguments? passed to the function in a & b both D
with the number of may be skipped.
correct positional order.
arguments specified in
the function definition
33. def person(name, age, salary):
print(“Name: ”, name)
print(“Age: ”, age) person(salary=50000, person(‘Amit’ , 30,
34 person(‘Amit’ , 30) None of the above A
print(“Salary: ”, salary) name=”Ajay”, age=30) 50000)
which of the following is example of function calling in Keyword argument?

34. def car (model, cost=500000):


print(“Model: ”, model)
Model: Maruti
print(“Cost: ”, cost) Model: Maruti Model: Maruti Cost:
Cost: 250000
Cost: 250000 250000
35 Model: Honda City None of the above A
display(cost=250000, model=”Maruti”) # call statement Model: Honda City Model: Honda City
Cost: 500000
display(”Honda city”)
What is the Output of above program?
def person(name, age):
print(“Name: ”, name)
print(“Age: ”, age) person( name=”Ajay”,
36 person(‘Amit’ , 30) person(‘Amit’ ) None of the above B
age=30)
which of the following is example of function calling in Required argument?

* symbol is used to
Number of arguments
Number of arguments in specify variable-length
37 What are the characteristics of Variable-length Arguments? in call are not fixed Option b & c both D
call are fixed length argument in function
length
header
What is the output of following Program?
def fun(a, *tup):
res = a
for i in tup:
38 10 20 24 12 C
res = res * i
print(res)
fun(1, 2, 3, 4) # call to function fun()

It returns the identity of Every object doesn’t


39 Which of the following is the use of id() function in python? Both a & b None of the above A
the object have a unique id
def f() :
for i in ‘welcome’ :
40 print (i , end=’ ‘ ) welcome welcome Welcome None of these B
f() # function call

41 In range(0,100,5) name of the function is------and it has----arguments range,3 range,2 range,4 None of these A
42 --------error is causedby importing an unknown module ExportError ImportError Both a & b None B
43 ---------consists of a function header followed by function function name Parameter list return value Function definition D
44 user defined functions are created by using the ____keyword lambda def user None of these B
45 The_____is used to uniquely identify the function arguments calling function function name All of these C
46 The --------describe what the function does. docstring keyword called function Both A & B A
Fill in the blanks to define a function name display--------------
47 display( )-----------print def, : deff, : definition, : function name , : A
("Hello World")
48 After the called function is executed, the control is returned back to the-------- called program calling program return value parameter list B
49 A return statement with no arguments is the same as return ------ 0 3 None 2 C
50 Before calling a function, you must ------------it. call it return it call again define D
--------variable can be accessed from point of its definition until the end of the function in
51 global local # None of these B
which it is defined.
52 To define a variable defined inside a function as global,------statement is used. local variable global All of these C
53 Every function has an implicit------statement as the last instruction in the function body called program calling program return def C
54 Any formal parameters written after the variable - length arguments must be ------arguments default argument required argument variable length argument keyword-only D
55 --------are not declared as other functions using the def keyword Lambda functions user defined function local function global function A
56 This docstring specified can be accessed through the -----attribute of the function document documentation -----doc----- All of these C
57 You can find the name of a module by using the -----attribute of the module keyword Parameter list function name ----name----- D
58 ----------is a built-in function that lists the identifiers defined in a module random( ) print( ) sqrt( ) dir( ) D
59 Every package in python is a directory which must have a special file called--------- init----- -----init--- -----init----.py .py C
Packages have an attribute-------which is initialized with a list having the name of the directory #package
60 ----path---- import Module B
holding the ------init----.py file
Fill in the blanks to define a function that takes two arguments and prints their sum--------------
61 def, :, y lambda, : ,x+y x+y None of these A
mult(x,y)------------print(x*---)
Fill in the blanks to define a function that prints "Positive", if its parameter is greater than 0
and "Negative " otherwise
--------pos_neg(x):
62 if x>0: def,print, else: if, else print( ) deff A
-----------("Positive")
--------
print(" Negative ")
Fill in the blanks to define a function that compares the length of its arguments and returns the
longest one.
def max_len(x,y):
63 if len(x) >=-----(y): return len len, return, return None of these C
--------x
else:
---------y
Fill in the blanks to pass the function cube as an argument to the function "test".------cube(x):
return x*x*x
64 def do (func, x)------ lambda, :, cube def,:, cube x*x*x All of these B
print(func(x))
do(---------,2)
frommath import sqrt,
65 To import the sqrt and cos function from the math module, write-------- import math from import sqrt( ), cos( ) B
cos
66 python's preinstalled modules forms the --------- standard function standard modules standard library standards C
Fill in the blanks to calculate x*(x+1)using lambda function and call it for the number 10 res
67 =(-------x: x------(x+1))-------- lambda, *, (10) lambda, *, (12) lambda, *, (14) None of these A
print(res)
68 The -----command is used to force the reloading of a given module upload reload download All of these B
69 -------,---------, and ------namespaces may exist during te execution of any given python program local global Built-in, global, local Built-in C
How many times print statement executes
def display ():
print('a')
70 print('b') 1 2 3 4 B
return
print('c')
print('d ')
import random as r
71 An error occures 1 10 Any random value A
print(random.randomint(1,10))
72 How would you refer to the sqrt function if it was imported by writing like this___ square_root math.sqrt sqrt square_root B
how many numbers are display def
display(x):
for i in range(x):
73 0 1 9 10 D
print(i)
return
display(10)
74 Which statement invokes the function? Function Defination Function call Function header __doc__ B
75 __of variable determines the part of the in which it is accessible Scope Lifetime Data type Value A
76 Arbitrary arguments have which symbol in the function defination before the parameter name & # % * D
77 Modules are files saved with ____ extension .py mod md1 imp A
78 This import * statement import all names in the module except those beginning with__ % $ _ ! C
79 PyPI stands for Python Project Index Python Package Installer Python Package Index Package Python Installer C
80 Identify the correct way of calling a function named display() that prints Hello on the screen print(display) displayHello result=display() displayHello() C
81 Which keyword is used for function define fun def function C
82 Which of the following items are present in the function header? function name parameter list return value Both A and B D
83 If return statement is not used inside the function, the function will return None 0 Null Abitrary Value A
84 Which of the following function headers is correct? def fun(a = 2, b = 3, c) def fun(a = 2, b, c = 3) def fun(a, b = 2, c = 3) def fun(a, b, c = 3, d) C
function
85 Which one of the following is the correct way of calling a function? function_name() call function_name() ret function_name() A
function_name()
86 Which operator is used in Python to import modules from packages? . * ^ $ B
Lambda is a function in
87 Lambda is function in python TRUE FALSE python but user can not None of these A
use it.
Id returns the identity of Every object doesn’t
88 Which of the following is the use of id() function in python? All of above None of these A
the object have a unique id
Find Output
num = 10
def show():
var = 20
In Function var is - 10
89 print("In Function var is - ", num)
Outside function, var is - 10
show()
print("Outside function, var is - ", num)
def f():
s = "Hello World!"
print(s)
Hello World!
90
Welcome to Python Programming
s = "Welcome to Python Programming"
f()
print(s)
def f():
global var
print(var)
var = 10 100
91
print(var) 10

var = 100
f()
def sqr(x):
print(x*x)
92 100
sqr(10)

def mul_twice(x,y):
print(x*y)
50
93 print(x*y)
50
mul_twice(5, 10)
def func():
global x
print("x =", x)
x = 100 x = 10
94 print('x is now = ', x) x is now = 100
x = 100
x = 10
func()
print('x =', x)
def func1():
var = 3
func2(var)

def func2(var):
95 3
print(var)

func1()

def func(x):
print('x = ', x)
x = 100
x = 50
print('In Function, x after modification = ', x)
96 In Function, x after modification = 100
Outside Function, x = 50
x = 50
func(x)
print('Outside Function, x = ', x)
def sum(num1, num2):
total = num1 + num2
print("Inside function, Total = ", total)
Inside function, Total = 30
return total
97 Outside the function, Total = 30
total = sum(10, 20)
print("Outside the function, Total = ", total)

def min(x,y):
if x<y:
return x
98 else: 4
return y
print(min(4, 7))

def add(x, y):


sum = x + y
return sum
99 30
print(“This won’t be printed”)
print(add(10,20))

def say(message, repeat_it = 2):


print(message * repeat_it)
HelloHello
100
HelloHelloHelloHelloHello
say('Hello')
say('Hello', 5)
def func(x, y = 100, z = 1000):
print('x = ', x, ' y = ', y, 'and z = ', z)
x = 5 y = 15 and z = 25
101 x = 35 y = 100 and z = 55
func(5, 15, 25)
x = 200 y = 70 and z = 1000
func(35, z = 55)
func(y = 70, x = 200)
expo_3 = lambda x: x ** 3
102 print(expo_3(5)) 125

def func():
"""Do nothing.
Do nothing.
103 Nothing doing. """
pass Nothing doing.

print(func.__doc__)
def is_even(x): if x==0:
return True
else:
return is_odd(x-1)

104 TRUE
def is_odd(x):
return not is_even(x)

print(is_even(22))
True or False
105 It is mandatory to place all import statements at the beginning of a module. TRUE FALSE B
With the "import modulename" statement, any item from the imported module must be
106 TRUE FALSE A
prefixed with module name.
107 All python standard library modules must be imported before any programmer-defined modules. TRUE FALSE B
If a particular module is imported more than once in a python program, the interpreter will load
108 TRUE FALSE A
the module only once
109 A function can be called from anywhere within a program. TRUE FALSE A
110 A statement can call more than one function. TRUE FALSE A
111 Function calls may contain arguments that are function calls. TRUE FALSE A
112 All functions that returns a value must accept atleast one parameter. TRUE FALSE B
113 Docstring can contain multiple lines of text. TRUE FALSE A
114 Every function can be written more or less indenpendently of the others. TRUE FALSE A
115 When function call is encountered , the control jumps to the calling function. TRUE FALSE B
116 A function can call only one function TRUE FALSE B
117 code reuse is one of the most prminent reason to use function. TRUE FALSE A
118 Large program usually follow the WET principle. TRUE FALSE B
119 we can have a function that does not take any inputs at all . TRUE FALSE A
120 The calling function may or may not pass pararmeters to the called function. TRUE FALSE A
121 The return statement is optional TRUE FALSE A
122 Python does not allow you to assign the function name to variable. TRUE FALSE B
123 Names of variable in function call and header of function definition may vary. TRUE FALSE A
124 Arguments may be passed in the form of expressions to the called function. TRUE FALSE A
125 You can have a variable with the same name as that of a global variable in the program. TRUE FALSE A
126 You should make extentsive use of global variables & global statements. TRUE FALSE
127 The return statement can be used outside of a function definition. TRUE FALSE B
128 Any code written after the return statement is never excuted. TRUE FALSE A
129 The order of keyword argument is not importatnt. TRUE FALSE A
130 Default argument should always be written after the non default arguments. TRUE FALSE A
131 You can specify only one default argument in your function. TRUE FALSE B
The variable length argument if present in the function definition should be first in the list of
132 TRUE FALSE B
formal parameters.
133 A function can not be used on th left side of an assignment statement. TRUE FALSE B
134 Lambda functions are throw- away functions. TRUE FALSE A
135 Lambda functions can be used wherever function objects are required . TRUE FALSE A
136 Lambda functions can not access global variables. TRUE FALSE A
137 Lambda function performs better than regular functions. TRUE FALSE B
A recursive function takes more memory & time to execute as compared to its non-recursive
138 TRUE FALSE A
counterpart.
Dr. D. Y. Patil Institute of Technology, Pimpri, Pune -18
Department of First Year Engineering
Sub: Programming and Problem Solving
Unit - 4 MCQ

Q. No. Question Option A Option B Option C Option D Ans.


1 Strings are immutable objects in Python True False A
Python does not support a character type; a single character is treated as strings of
2 False True B
length one.
3 String is a sequence made up of one or more____________________________. Alphabets Characters Digits Whitespaces B
Individual characters in a string are accessed using the
4 Slicing Range Slicing both None of given A
___________________operator.
If we access the string from the first character then we use a ________based index
5 Positive, -1 negative , 0 slicing, 1 pointer 1 A
but when doing it backward the index starts with -_______.______.
6 Strings are stored in memory in _______________memory locations. Alternate Alternate Consecutive None of the above C
7 Each character in string can be accessed by ________________. Using format() Positive Indexing Negative Indexing Either b) or c) D
8 String Indices always starts with ______. 0 1 either 1) or 2) None of the above A
9 Last location index in string is calculated as________________. Len(string)-1 Len(string)-2 Len(string)+1 None of above. A
Data stored can be Data stored can not Data stored can be
10 Strings are Immutable means ________________ None of the above. B
modified. be modified altered.
11 String is ___________in python. Built-in function Function Data type None of the above C
12 Which of the following are string operations_____ Concatenation(+) Slice([]) Range Slice([:]) All the above D
13 Guess the correct output of the following String Operations: TypeError:
13 str1=”welcome” unsupported welcomewelcome welcome welcome None of above B
print(str1+str1) operand
Select the correct output of the following String Operations
14 str1=”Python Programming” p n g y C
print(str1[-1])
15 15 Which operator is used to repeat a string n number of times + += [] * D
16 Select the correct output of the following String Operations
str1=”Welcome to the World of Python”
str2=”to”
16 if str2 in str1: TRUE found FALSE not found B
print(“found”)
else:
print(“not found”)
17 _____ and ______ operators are known as membership operator in , not in is , is not ==, != [] , [:] A
18 Select the correct output of the following String Operations
18 str1=”Problem solving & python programming” roble Problem Proble roblem A
print(str1[1 :6 ])
19 The index of first character and last character in the string of length n is respectively 0, 0 0, n-1 1,n 1,n-1 B
Select the correct output of the following String Operations
str1=”Welcome to the World of Python”
str2=”too”
20 if str2 not in str1: True FALSE found not found C
print(“found”)
else:
print(“not found”)
21 In python a string is appended to another string by operator……. + * [] += D
What is the output of the following string comparison True False
22 print("John" > "Jhon") False True A
print("Emma" < "Emm")
Select the correct output of the following String operations
strOne = str("pynative")
23 strTwo = "pynative" false false true true true false false true B
print(strOne == strTwo)
print(strOne is strTwo)
Find out the output of following programme:
first_str='Kunal works at PHOENIX'
second_str='Kunal works at Phoenix'
Both Strings are Both Strings are
24 B
if first_str==second_str: Same Different
print("Both Strings are Same")
else:
print("Both Strings are Different")
Find out the output of following programme:
first_str= 'Kunal works at Phoenix'
second_str='Kunal works at Phoenix'
Both Strings are Both Strings are
25 if first_str!=second_str: A
Same Different
print("Both Strings are Different ")
else:
print("Both Strings are Same ")

Find out the output of following programm


name1=”Kunal”
26 name2=”Shreya” Both are same False Both are same True A

print(“Both are same”,name1 is name2)


Find out the output of following programme:
name1=”Kunal”
27 name2=”Kunal” Both are same False Both are same True A

print(“Both are same”,name1 is name2)


28 28. Strings are compared by using ASCII value of the characters. TRUE FALSE A
29 The ___ function returns a list of lines in the string. split() splitlines() strip() endswith() B
30 ___ function toggles the case of every character. upper() lower() swapcase() isalpha() C
31 ___ function returns the ASCII code of the character. chr() isalnum() isalpha() ord() D
endswith (beg, end, endswith (suffix, endswith (beg, end, endswith (suffix,
32 What is correct syntax of endswith() D
suffix) beg, end) stride) beg, end)
return true if every convert lowercase return true if any
convert string to
33 islower() is used to character in the character to upper one character of a B
lower case
string is lower case case string is lower case
34 Which function removes all trailing white spaces in the string. rstrip() lstrip() strip() split() A
Select the correct program to enumerate a string. print(str.enumerate( print(enumerate.str(l print(list(enumerate print(list(enumerate
35 D
str="Hello World" list)) ist)) ()) (str))
Which is the correct function and syntax to check if string has atleast one character
36 and every character is either a number or an alphabet and false otherwise? print(str.isalnum()) print(isalnum(str)) print(str.isalpha()) print(str.isdigit()) A
str="JamesBond007"
37 Which function returns length of the string? len(str) length(str) endswith() None of the above A
strip() and
38 "Cool" becomes "COOL", which two functions must have been applied? strip() and upper() strip() and lower() lstrip() and rstrip() A
capitalize()
39 Identify the correct result from the following ord('10') = 50 chr(72) = 'H' chr(55) = 9 ord('z') = 123 B
what is the output of following code
40 str=”PYTHON” OH YTHON OHTYP YTH D
print(“8) str[-5 :-2 ]= “, str[ -5: -2])
41 Character in a string could be a letter, digit, whitespace, or any other symbol. TRUE FALSE A
Python treats strings as contiguous series of characters delimited by single or double
42 TRUE FALSE B
quotes but not triple quotes.
43 Python has a built-in string class as well as a string module that has many methods. TRUE FALSE A
Index can either be an integer or an expression that evalates to a floating point
44 TRUE FALSE B
number.
45 In a string, all white space characters are also assigned an index value. TRUE FALSE A
46 Raw strings do not process escape sequences. TRUE FALSE A
47 'r' is used as a prefix for unicode strings. TRUE FALSE B
48 We cannot delete or remove characters from a string. TRUE FALSE A
The % operator takes a format string on the right and the corresponding values in a
49 TRUE FALSE B
tuple on the left.
Conversion specifications start with a % operator and can appear anywhere in a
50 TRUE FALSE A
string.
The number and type of values in a tuple should match the number and type of
51 TRUE FALSE A
format sequences or conversion specifications in a string.
52 The - after each % in the conversion string indicates right justification. TRUE FALSE B
53 You can access a string using negative indexes. TRUE FALSE A
54 ord() function returns character represented by a ASCII number. TRUE FALSE B
55 A string is a substring itself. TRUE FALSE A
56 Strings are compared based on ASCII values of their characters. TRUE FALSE A
57 The index of the first character in the string is------- 0 1 n-1 n A
58 The index of the last character in the string is------- 0 1 n-1 n C
59 Which error is generated when the index is not integer? IndexError NameError TypeError BoundError C
60 Which of the following word best means to add something at the end? Concatenate Append Join Add B
61 In python a string is appended to another string by using which operator? + * [] += D
62 Which operator is used to repeat a string n number of times? + * [] += B
63 The print statement prints one or more literals or values followed by a ---- Newline character Tab Whitespace Exclamation A
64 Which error is generated when a character in a string variable is moified? IndexError NameError TypeError BoundError C
65 You can delete the entire string using which keyword? del erase remove delete A
Which operator takes a format string on the left and the corresponding values in a
66 + * [] % D
tuple on the right?
67 Which character is used for hexadecimal integers in the format string? u x d s B
68 When using find( ), if str is not present in the string then what is returned? 0 -1 n-1 ValueError B
strip( ) and
69 "Cool" becomes "COOL" , which two functions must have been applied? strip( ) and upper( ) strip( ) and lower( ) lstrip( ) and rstrip( ) A
capitalize( )
In the split( ), if no delimiter is specified, then by default it splits string on which
70 whitespace comma newline colon A
characters?
71 The splitlines( ), split lines in strings on which characters? whitespace comma newline colon C
72 By default, the value of stride is--- 0 -1 1 n-1 C
73 To print the original string in reverse order, you can set the stride as---- 0 -1 1 n-1 B
74 Identify the correct result from the following ord ('10') = 50 chr (72) = 'H' chr(55) = 9 ord ( 'z' ) =123 B
s="Welcome" el elc elco None of these A
75
print(s[1:3])
s="Welcome"
76 We Wel Welc None of these B
print(s[:3])
s="Welcome" lcom come ome None of these C
77
print(s[4:])
str="Welcome" elco elcom D
78
print(s[1:-1])
str="Welcome" come FALSE TRUE None of these C
79
print("come" in str)
str="Welcome" come FALSE TRUE None of these B
80
print("come" not in str)
81 "free"=="freedom" TRUE free FALSE None of these C
82 "man"!="men" TRUE FALSE men None of these A
str="Welcome to Python" FALSE can't say
83 TRUE None of these B
print(str.isalnum())
84 "Hello".isalpha() TRUE FALSE hello None of these A
85 "14-10-2106".isdigit() true FALSE alpha None of these B
86 print("hello".islower()) TRUE FALSE hello None of these A
87 "\t".isspace() space FALSE t TRUE D
str="Hello" TRUE FALSE he None of these B
88
print(str.startswith("he"))
str="Hello ,welcome to the world of Python" -1
89 5 3 4 D
print(str.find("o"))
str="Hello ,welcome to the world of Python" 0 3
90 -1 None of these B
print(str.find("if"))
str="Hello ,welcome to the world of Python" 29
91 27 5 28 D
print(str.rfind("of"))
str="Hello ,welcome to the world of Python" 4
92 6 5 None of these A
print(str.count("o"))
93 "us" not in "success" TRUE FALSE us None of these A
94 "mi" in "ours" TRUE mi FALSE None of these C
for j in 'Python': python PP yy tt hh oo nn pythonpython None of these B
95
print(2*j,end=' ')
import string 6 8 None of these A
96 7
print(string.find("abcdabcdabcd","cd",3))
import string
97 8 9 10 None of these C
print(string.find("abcdabcdabcdabcdabcd","cd",7,13))
a=10
3**4=81 ,, 10 * 20 81 and 10 * 20 = 3**4=81 and 10 *
98 b=20 81200 D
= 200.000000 200 20 = 200.000000
print("3**4=%d and %d * %d = %f" % (3**4,a,b,a*b))
print("%d %f %s" % (7,15,28)) 7 15.000000 28 7 15.000000 28 7 15.000000 28 None of these A
print("%-.2f" % 369) 369.00 369.00 369.00
99 print("%-10.2f%-10.2f" % (91,23.456)) 91.00 23.46 91.00 23.46 91.00 23.46
print("%5.2f %5.2f $%5.2f" % (9, 1.2, 55.78) 9.00 1.20 9.00 1.20 9.00 $55.78
$55.78
str1='Welcome!'
str2='to Python'
100 Weon Weo We None of these A
str3=str1[:2]+str2[len(str2) - 2:]
print(str3)
101 print("She sells sea shells on the sea shore.".find("sea",3,-6)) 9 8 10 None of these C
102 len("She sells sea shells on the sea shore.") 29 38 37 None of these B
str="Welcome to the world of Python" 8 7 None of these
103 9 A
print(str[:10].find("t"))
str="Welcome to the world of Python" me to come to ome to
start=3
104 None of these B
end=10
print(str[start:end])
str="Hello" FalseTrue true true None of these A
105 print(str.startwith("h")) false false
print(str.lower().startswith('h'))
In %d years I have saved %g %s .'%(3, 4.5, 'lakh rupees') In 3 ,years I have In 3 years I have In 3,, years I have
106 saved 4.5 ,lakh saved 4.5 lakh saved 4.5 ,,lakh None of these B
rupees rupees .' rupees .'
, '.join(['Sun', 'Stars', 'Planets']) Sun StarsPlanets Sun,, StarsPlanets Sun, Stars, Planets' D
107 Sun, StarsPlanets'
'.join(['Welcome' , 'to', 'the', 'world', 'of', 'Python Welcome to Welcome , to , Welcome to
108 ! ']) the world of the , world of the , world , of , None of these A
Python! ' Python! ' Python! '
Hello'.join(['Welcome' , 'to', 'the', 'world', 'of', 'Python WelcomeHellotoHe Welcome,Hello,to,H WelcomeHellotoHe A
! ']) llotheHelloworldHe ellotheHelloworldH llotheHelloworldHe
109
lloofHelloPython! ' elloofHelloPython! ' llo,of,Hello,Python!
' None of these
"Good morning students".split() ['Good''morning' ['Good', 'morning', Goodmorning'stude B
110
'students'] 'students'] nts' None of these
111 String is a sequence made up of one or more____________________________. Alphabets Characters Digits Whitespaces B
Individual characters in a string are accessed using the
112 Slicing Range Slicing both None of given A
___________________operator.
113 _______ error is generated when index out of bounds is accessed. TypeError NameError out of Bound error IndexError D
114 _________ means to join together. Concatenation add join combine A
115 The ___ function is used to convert values of any other type into string type. str() string() convert() strs() A
116 The_____returns the memory address of that object. detail() type() id() show() C
117 A method is invoked or called on an_______. object class function def A
118 ______ function checks if the string ends with suffix. suffix() trace() end() endswith() D
119 ___ function toggles the case of every character. upper() lower() swapcase() isalpha() C
120 The ___ function returns a list of lines in the string. split() splitlines() strip() endswith() B
121 Omitting both ends in the slice operation means selecting the_______. entire string half string part of string slices of string A
If we access the string from the first character then we use a ________based index
122 Positive, -1 negative , 0 slicing, 1 pointer 1 A
but when doing it backward the index starts with________.
123 ___ function returns the ASCII code of the character. chr() isalnum() isalpha() ord() D
124 _____ and ______ operators are known as membership operator in , not in is , is not ==, != [] , [:] A
125 ____ function is used to know the details of a particular item. detail() type() dir() show() B
126 ______function displays the methods in a module. detail() type() dir() show() C
127 Strings are stored in memory in _______________memory locations. Alternate Alternate Consecutive None of the above C
128 Each character in string can be accessed by ________________. Using format() Positive Indexing Negative Indexing Either b) or c) D
129 String Indices always starts with ______. 0 1 either 1) or 2) None of the above A
130 Last location index in string is calculated as________________. Len(string)-1 Len(string)-2 Len(string)+1 None of above. A
Data stored can be Data stored can not Data stored can be
131 Strings are Immutable means ________________ None of the above. B
modified. be modified altered.
132 String is ___________in python. Built-in function Function Data type None of the above C
133 Which of the following are string operations_____ Concatenation(+) Slice([]) Range Slice([:]) All the above D
Dr. D. Y. Patil Institute of Technology, Pimpri, Pune -18
Department of First Year Engineering
Sub: Programming and Problem Solving
Unit - 5 MCQ

Q. No. Question Option A Option B Option C Option D Ans.


Multiple Choice questions
1 Which is the fastest and the most efficient language? Machine Level Assembly High Level Artificial Intelligence A
2 FORTRAN, COBOL and PASCAL are examples of which generation language? First Second Third Fourth C
In which generation language does the code comprise instructions written in English like
3
sentences? First Second Third Fourth D
4 Which feature is affected by Programming paradigm? style of programming capabilities Limitations All of these D
5 C and Pascal belong to which type of Programming Language? Monolithic structured logic oriented object oriented B
6 Which Paradigm holds data as a priority? Monolithic structured logic oriented object oriented D
7 Two objects can communicate with each other through classes objects methods messages D
Which concept enables programmers to assign a different meaning or usage to a
8
variable,function or object in different contexts? Inheritance Message Passing Polymorphism Abstraction C
which access level allows data and functions to be accessed only by the class in which it is
9
declared? public private protected none of these B
10 In which of this applications is OOP applied? CAD CAM Compiler Design All of these D
The high level language that is used for numeric,scientific,statistical and engineering
11
computations is C BASIC JAVA FORTRAN D
12 The most portable language is C BASIC JAVA FORTRAN C
13 Which of the following languages does not need any translator? Machine Langiuage 3GL Assembly Language 4GL A
14 The advantages of Modularization are Reusability Enhanced Productivity Less time to develop All of these D
15 You can use Python for Application Programming Web Programming Scientific computing All of these D
16 Which of the following creates a new type? classes objects attribute method A
17 Which type of error is caused by trying to access unknown attributes? ValueError NameError AttributeError TypeError C
18 Class members are accessed through which operator? % : * . D
19 Which method is automatically executedwhen an object of a class is created? _init_() _del_() _call_() _repr_() A
20 In which method should all variables be initialized? _init_() _del_() _call_() _repr_() A

21
If a class has one class variable,then how many copies will be created for that variable? 0 1 n infinite B
Which variables are usually used to keep a count of number of objects created from a
22 class? classes objects ordinary temporary A
23 Which method is automatically invoked when an object is about to be destroyed? _init_() _del_() _call_() _repr_() B
24 Which error is generated when an attempt is made to access an undefined method? ValueError NameError AttributeError TypeError C
True or False
A Programming language provides a blueprint to write a program to solve a particular
25 TRUE FALSE B
problem
26 Machine language is lowest level of language TRUE FALSE A
In monolithic paradigm,global data can be accessed and modified from any part of the
27 TRUE FALSE A
program
28 Monolithic programs has two modules TRUE FALSE B
29 Monolithic programs are easy to debug and maintain TRUE FALSE B
30 Structured programming is based on modularization TRUE FALSE A
31 Object oriented programming supports modularization TRUE FALSE A
32 Structured programming heavily used to goto statements TRUE FALSE B
33 Modules enhanced the programmers productivity TRUE FALSE A
34 A structured program takes more time to be written than other programs TRUE FALSE B
35 The interface specifies how to sed a message to the object TRUE FALSE B
36 OOP does not support modulerization TRUE FALSE B
37 A class is a user defined data type TRUE FALSE A
38 TRUE FALSE B
Once a class is declared ,a programmer can create maximum 10 objects of that class
39 Polymorphism means several different forms TRUE FALSE A
Any data or function with access level private can be accessed only by that class or by
40 TRUE FALSE B
any class that inherited from it
41 OOPS helps to develop secured programs TRUE FALSE A
42 It is difficult to manage software complexity in object oriented programs TRUE FALSE B
43 TRUE FALSE A
Programs written using object oriented language have greater processing overhead
44 Python supports OOP TRUE FALSE A
Find output
class Employee:
deptt = 'IT'
def __init__(self, name):
self.name = name
45 Raghav IT
E1 = Employee('Raghav')
print(E1.name, end=" ")
print(E1.deptt)
class Car:
def __init__(self, company, model):
self.company = company
46 Swift Dzire ZX
self.model = model
Dzire = Car('Maruti', 'Swift Dzire ZX')
print(Dzire.model)

class Car:
company = "Maruti"
def __init__(self, model, year = 2016):
self.model = model
47 Company - Maruti, Model - Swift Dzire ZX, Year - 2016
self.year = year
def display(self):
print("Company - %s, Model - %s, Year - %d" %(self.company, self.model, self.year))
Dzire = Car('Swift Dzire ZX')
Dzire.display()
class ABC():
def __init__(self, var):
self. var = var
def display(self):
48 From class method, Var = 10
print("From class method, Var = ", self. var)
obj = ABC(10)
obj.display()
class Person():
def __init__(self, name):
self. name = name
def display(self):
49 print("Good Morning ", self. name) Good Morning Roy
def greet(self):
self.display()
obj = Person("Roy")
obj.greet()
Fill in the blanks
Programming languages have a vocabulary of_____ and______for instructing a
50 syntax, semantics
computer to perform specific tasks.
51 ______ is used to covert assembly level program in to machine language. Assembler
______and_____ are used to translate the instructions written in high level
52 Complier, interpreter
language into computer executable machine language.
53 _______ defines the structures of a program Programming paradigm
54 _______programming emphasizes on classes and objects. Object Oriented
Two examples of languages that support monolithic programming paradigm
55 Assembly language and BASIC
are_____and____
56 Functional abstraction was first supported by _______ programming. Structured
57 An object contains_______ and _______. Data Methods
58 ______ paradigm supports bottom-up approach of problem solving . OOP
59 ______ provides a template that describes the structure and behaviour of an object. Class
60 while______is a logical structure, ________is a physical actuality. Class, Object
61 State defines the ________ values of its attributes at a particular time
62 The data that is transferred with the message is called _________. parameter
the receiver object, the name of the method that the receiver should invoke and the parameters that must be
63 A message consists of _____, _______, and _______.
used with the method
64 Inheritance relation is also called as _________ relation. is-a
65 ______ is related to classes and their hierarchy. Inheritance
66 Polymorphism is related to _________. Methods
Any data or function with access level ______ can be accessed by any function
67 Public
belonging to any class
68 Program written in _______ are robust, secure and reliable. Python
69 In python , the word polymorphism is often is used with _______. Inheritance
Dr. D. Y. Patil Institute of Technology, Pimpri, Pune -18
Department of First Year Engineering
Sub: Programming and Problem Solving
Unit - 6 MCQ

Q. No. Question Answer


Fill in the blanks
_________________function is
1 open()
used to access the file
________open("File.txt")___file:
2 with,as
data=file.read()
Fill in blanks to open a file called "abc.bin" in binary mode .
3 "abc.bin","rb"
File =open(_________,________)
How many characters would be printed by this code(One character in one byte)?
File=open("FILE.txt","r")
for I in range(100):
4 10
print(file.read(10))
file.close()

Fill in the blanks to open a file,read its content,and print its length
file=___________("File.txt","r")
text=file._____()
5 open,read,len
print(_______(text))
file.close()

Fill in the blanks to open a file for reading


using the with statement.
6 with,as,read
________open("File.txt")___file:
print(file.____())
Most file systems that are used today
7 tree(or hierarchical)
stores file in a ___ strucure.
8 Every file is identified by its path that begins from the ____. root node or the root folder
9 In Windows,_____ is the root folder c:\(also known as C drive)
A relative path is specified relative
10 current working directory
to the programs ______.
_____pathnames starts with respect
11 Relative
to the current working directory
Each fie ends with a special character
12 end-of-file(EOF) marker
called the ____.
13 open() function returns a_______ file object
The _____method frees up any system
14 close()
resources such as file descriptors ,file locks,etc
Any attempt to use the file object will
15 ValueError
result in a _______
16 The write() method returns________ None
If you try to open a file for reading that
17 IOError
does not exist ,then you will get______
The readline() method returns ___when
18 an empty string
the end of the file has been reached.
If you do not want the new file to be
19 path
created in the current working directory ,then you must specify the ____
The ___specifies the location from
20 file pointer
where the current read or write operation is initiated
_____method tells the current position
21 within the file at which the next read tell()
or write operation will occure
When you open file for reading, the
22 location 0
file pointer is posioned at______.
23 ____ method is used to delete a file remove()
If you try to change to a directory that
24 WindowsError
does not exist,___will be generated
25 If you try to delete a non empty directory ,then you will get ____. OSError
To remove a non empty directory,use
26 rmtree(),shutil
the ____ method defined inside the ___ module
27 The method ____ is used to create more than one folder mkdirs()
____ method is used to create a strings
28 os.path.join()
for filenames
The _____method uses the string value
29 os.path.abspath()
passed to it to form an absolute path.
Find Output
import os C:\Users\Students\BTech
Files = ['BTech.txt', 'BCA.csv', 'BSc.docx'] .txt
for file in Files: C:\Users\Students\BCA.c
print(os.path.join('C:\\Users\\Students', file)) sv
30
C:\Users\Students\BSc.d
ocx

with open("File.txt", "w") as file: Greetings to All !!!


file.write("Greetings to All !!! \n Welcome to the world of programming\n") Welcome to the world
31 with open("File.txt") as file: of programming
print(file.read())

file=open("File.txt", "r")
file.read()
text = file.read()
print(len(text))
32 file.close() 0
str ="Welcome to Python Programming"
file = open("File.txt","w")
n = file.write(str)
33 print(n) 29
file.close()

What will be written in the file?


34 file.write("Oxford" + " University" + "Press") Oxford University Press

What will be written in the file?


file.write(str(len("Oxford University Press")))
35 23

Blue
36 What will be written in the file?
file.write("Clue".replace('C', 'B')
What will be written in the file?
37 hello
file.write("HELLO".lower())
True or False
38 When a program is being executed, its data is stored in ROM. FALSE
39 Ram is an example of non-volatile memory. FALSE
40 You can have only one root in all the file systems. FALSE
41 Delimiters may vary from one operating System to another. TRUE
42 Folder names and file names are case insensitive in Windows. FALSE
43 Absolute path always contains the root. TRUE
44 The contents of a binary file are human readable. FALSE
Text files includes files like word processing documents,PDF's, spreadsheets,
45
videos, zip files, and other executable programs. FALSE
46 Binary files are more efficient than text files. TRUE
47 *.py files are binary files. FALSE
48 When you open a file for appending that doesnot exist, then a new file is created. TRUE
49 You can open any number of fileswithout any sort of restriction. FALSE
50 The read() starts reading from the beginning of the file. TRUE
If count is missing or have anegative value in the read() then, no contents are read
51
from the file. FALSE
52 The readlines() is used to read all the lines in the file. FALSE
53 The tell() methos moves the file pointer to the new location. FALSE
54 Before removing a directory, it should be absolutely empty. TRUE
os.path.abs() methos accepts a file path as an argument and returns True if the file
55
path is an absolute pathand False otherwise. FALSE
56 The cwd() method is used to display current working directory. FALSE
MCQ Option C Option D Ans
close(fil close("fil file.close
57 Identify the right way to close a file file.close() A
e) e") d
If the file.txt has 10 lines written in it, what will be the result?
58 1 0 10 2 C
len(open("file.txt").readlines())
data
will be
written
to a file error
file will
that has will be
59 If a file opened in 'w' mode does not exist,then nothing will happen be B
name a generate
created
similar d
to the
specified
name
wite("W file.write "Welcom
wite(file,"Welcome to elcome ("Welco e to
60 Identify the right way to write "Welcome to python " in a file? C
python") to me to python".
python",f python") write(fil
A blank
Nothing line is An error
61 What will happen when a file is opened in write mode & then immediately closed? File contents are deleted A
happens written occurs
to the file
secondar
62 A file is stored in ________memory. primary cache volatile B
y
Hard Pen
63 ________ is an example of volatile memory RAM DVD A
disk drive
BTech_C Under
64 In the path C:\Students\Under Graduate\Btech_CS.docx,_____is the sub-folder C: Students D
S Graduate
65 Identify the delimeter in the Solaris file system / \ : | A
66 The default access mode is_______ r w rb wb A
current
python
67 By default, a new file is created in which directory root directory working D drive B
directory
directory
readline( readlines
68 which method is used to read a single line from the file? read() reads() B
) ()
readlines all of
69 which method is used to read to display entire contents of the file read() list() D
() these
In the seek() method, what will be the value of from if you want to specify number
70 0 1 2 3 B
of bytes from the current location of the file pointer?
os.path.b
os.path.r os.path.a
71 Which method returns a string that inculdes everthing specified in the path? os.path.dirname(path) asename( A
elpath() bs()
path)

You might also like