You are on page 1of 6

FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)

COMMON ASSESSMENT TEST -2


ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
9. A variable with a local scope can be used
1. In which of the following loop in python, we can
check the condition ? a) only within the b) outside the function
function
a) For loop b) While loop
c) none of these d) Both A and B
c) Do while loop d) None of the above
10. _____is defined as sequence of characters
2. Which of the following is a valid for loop in Python? represented in quotation marks (either single
quotes ( ‘ ) or double quotes ( “ ).
a) for(i=0; i < n; i++) b) for i in range(0,5):
a) Characters b) String
c) for i in range(0,5) d) for i in range(5)
c) Integers d) None of these
3. A while loop in Python is used for what type of
iteration? 11. Which of the following would give an error?

a) indefinite b) discriminant a) list1=[] b) list1=[]*3

c) definite d) indeterminate c) list1=[2,8,7] d) None of these

4. When does the else statement written after loop 12. Identify the operations in List
executes?
a) Indexing b) Slicing
a) When break b) When loop condition
statement is becomes false c) Concatenation d) All of these
executed in the loop
13. What is the purpose of slicing?
c) Else statement is d) None of the above
always executed a) Printing a part of b) Adding and printing
the list. the items of two lists.
5. What does break statement do?
c) Create a multiple d) All of these
a) repeat b) skip copies of the same
list.
c) stop d) print
14. _____ operation extracts a subset of elements from
6. A function that returns a value is called_____ an list and packages them as another list.

a) User-defined b) fruitful function. a) Concatenation b) List Slicing


function
c) append d) All of these
c) None of these d) Both A and B
15. To add a new element to a list we use which
7. Code that appears after a return statement, or any command?
other place the flow of execution can never reach,
is called ____ a) list1.add(5) b) list1.append(5)

a) Void b) Static c) list1.addLast(5) d) list1.addEnd(5)

c) Dead Code d) None of these 16. Identify the method to add all elements of a list to
the another list.
8. Which of the following is incorrect way of using an
argument while defining a function in Python, a) a.extend(b) b) Add(b)
where var1 and var2 are two arguments?
c) Both A and B d) None of these
a) def fn(var1, var2) b) def fn(var1, var2=5)
17. Identify the method that returns the index of the
c) def fn(*var1, var2) d) def fn(var1,*var2) first matched item
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
a) index() b) a.index(element) 26. An element in the dictionary has a ___

c) Add() d) None of these a) Key:value pair b) Reference:value pair

18. Identify the method that Reverses the order of c) Key:reference pair d) None of these
items in the list
27. All elements in the dictionary are placed inside the
a) a.reverse() b) Change() ___

c) Modify() d) All of these a) curly braces i.e. b) Square Brackets i.e.


{} []
19. Identify the method that returns the count of the
number of items passed as an argument c) brackets i.e. ( ) d) All of these

a) Count() b) a.count(element) 28. Keys in the dictionaries must be

c) add(element) d) None of these a) Mutable data type b) immutable data type

20. Suppose list1 is [3, 4, 5, 20, 5], what is c) Both a and b d) None of these
list1.index(5)?
29. The method used to add the dictionary with the
a) 0 b) 4 existing dictionary

c) 1 d) 2 a) a.update(dictionar b) edit(Dictionary)
y)
21. _____is a process of making a copy of the list
without modifying the original list. c) Change(dictionary) d) None of these

a) Aliasing b) copying 30. Write a list comprehension for number and its cube
for l=[1, 2, 3, 4, 5, 6, 7, 8, 9].
c) Cloning d) All of these
a) [x**3 for x in l] b) [x^3 for x in l]
22. Passing a list as an argument actually passes a
_____________________ c) [x**3 in l] d) [x^3 in l]

a) passes a reference b) passes a values to the 31. To open a file c:\scores.txt for reading, we use
to the list, not a list, not a reference of _____________
copy of the list. the list.
a) infile = b) infile =
c) passes a values to d) None of these open(“c:\scores.txt”, open(“c:\\scores.tx
the list. “r”) t”, “r”)

23. A tuple is ____________


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

c) Changeable d) None of these 32. Identify the features of Text files

24. ______can be used as keys in dictionaries a) Human-readable b) File processed using


text editor
a) List b) Tuples
c) Structured as a d) All of these
c) Both d) None of these sequence of
characters
25. What will be the output of below Python code?
tuple1=(2,4,3)tuple3=tuple1*2print(tuple3) 33. A _____is a sequence of characters stored on a
permanent medium like a hard drive, flash memory,
a) (4,8,6) b) (2,2,4,4,3,3) or CD-ROM.

c) (2,4,3,2,4,3) d) Error a) textfile b) Binary file


FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
c) Readable file d) All of these a) when a file we try to b) dividing a number by
open does not exist zero
34. Overwrite the contents of file with new contents by (FileNotFoundError) (ZeroDivisionError)
opening a file using ____
c) module we try to d) All of these
a) Read mode b) Append mode import is not found
(ImportError)
c) write mode d) None of these
43. Python exception that Raised when attribute
35. WhTo read two characters from a file object infile, assignment or reference fails
we use ____________
a) AttributeError b) FloatingPointError
a) infile.read(2) b) infile.read()
c) ImportError d) IndexError
c) infile.readline() d) infile.readlines()
44. ____is a file containing Python definitions and
36. Identify to function to determine whether a file statements
exists.
a) A file b) A data
a) isfile() b) Is.file()
c) A module d) All of these
c) Fileexist() d) Is.fileexist()
45. Is the following Python code valid?
37. Identify the module used for command line try:
arguments # Do something
except:
a) system b) cons # Do something
finally:
c) sys d) All of these # Do something

38. ____is any issue that arises unexpectedly that a) no, there is no such b) no, finally cannot be
causes a computer to not function properly. thing as finally used with except

a) A mistake b) A fault c) no, finally must d) Yes


come before except
c) An error d) All of these
46. _____is a collection of modules
39. Identify the basic errors
a) A package b) Nested module
a) Syntax error(parsing b) Exception(Runtime
errors) errors) c) files d) All of these

c) Both a and b d) None of these 47. The main difference between a module and a
package is that a package is
40. How many except statements can a try-except
block have? a) A collection of files b) Collection of modules

a) Zero b) One c) A collection of d) All of these


modules AND it has
c) More than one d) More than zero an __init__.py file.

41. Errors can also occur at runtime and these are 48. When is the finally block executed?
called ____
a) when there is no b) when there is an
a) exceptions b) Syntax error exception exception

c) semantic error d) None of these c) only if some d) always


condition that has
42. Identify the possible exceptions at runtime been specified is
satisfied
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
49 It is a process that enables a program to deal with a) prints all the vowels b) prints all the
the exceptions and continue its normal execution. in my_string consonants in
my_string
a) Identifying the error b) handling exception
c) prints all d) prints only on
c) Both a and b d) None of these characters of executing print(k)
my_string that
50. Can one block of except statements handle multiple aren’t vowels
exception?
56. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is
a) yes, like except b) yes, like except len(listExample)?
TypeError, [TypeError,
SyntaxError [,…] SyntaxError] a) 5 b) 4

c) no d) none of the mentioned c) Error d) None

51. What will be the output of the following Python 57. Suppose list1 is [1, 5, 9], what is sum(list1)?
code?
for i in range(0,2,-1): a) 1 b) 9
print("India")
Note: Q.No 51 to 75 Carries 2 Marks c) 15 d) None of these

a) India b) India India 58. Which of the following two Python codes will give
same output?
c) No Output d) Error (i) print(tupl[:-1])
(ii) print(tupl[0:5])
52. What will be the output of the following code? (iii) print(tupl[0:4])
Which of the following sequences would be (iv) print(tupl[-4:])
generated be the given line of code? if tupl=(5,3,1,9,0)
x="abcdef"
i="i" a) i,ii b) ii,iv
while i in x:
print(i,end="") c) i,iv d) i, iii

a) abcdef b) abcdef 59. What will be the output of the following


c) i i i i i..... d) No Output Python code
53. What will be the output of the following code?
x="abcd" >>>t=(1,2,4,3)
for i in range(len(x)):
print(i)
>>>t[1:-1]
a) abcd b) 0123

c) 1234 d) abcd a) (1, 2) b) (1,2,4)

54. What will be the output of the following code? c) (2,4) d) (2,4,3)
x=5
for i in x: 60. What is the output of print(k) in the following
print(i) Python code snippet?

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


print(k)
c) Error d) None of the above
a) all characters of b) list of Trues
55. What will be the output of the following Python my_string that
code snippet? aren’t vowels
k = [print(i) for i in my_string if i not in "aeiou"]
c) a list of Nones d) list of Falses
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
61. What will be the output of the following Python The multiplied
code? value is 12
>>>t = (1, 2)
>>>2 * t 67. Identify the error in the following code
>>> if a < 3
a) (1, 2, 1, 2) b) [1, 2, 1, 2] >>>print(a)

c) (1, 1, 2, 2) d) [1, 1, 2, 2] a) Bracket is missing b) No error

62. What will be the output of the following Python c) a colon is missing d) None of these
code snippet? in the if statement
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45} 68. What will be the output of the following Python
d1 > d2 code?

a) True b) False f = None


for i in range (5):
c) Error d) None with open("data.txt", "w") as f:
if i > 2:
63. Suppose d = {“john”:40, “peter”:45}. To obtain the break
number of entries in dictionary which command do print(f.closed)
we use?
a) True b) False
a) d.size() b) len(d)
c) None d) Error
c) size(d) d) d.len()
69. To read the next line of the file from a file object
64. What will be the output of the following Python infile, we use ____________
code snippet?
a) infile.read(2) b) infile.read()
d = {"john":40, "peter":45}
print(list(d.keys())) c) infile.readline() d) infile.readlines()

a) [“john”, “peter”] b) [“john”:40, “peter”:45] 70. What will be the output of the following Python
code snippet?

c) (“john”, “peter”) d) (“john”:40, “peter”:45) X=”hi”


print(“05d”%X)
65. What will be the output of the following Python
code snippet?(Shell execution) a) 00000hi b) 000hi

d = {"john":40, "peter":45} c) hi000 d) error


d["john"]
71. Find the output of the following program
a) 40 b) 45 import sys
m1=int(sys.argv[1])
c) "john" d) "peter" m2=int(sys.argv[2])
m3=m1*m2
66. Find the output of the program print('The multiplied value is: %d' %(m3))
import sys
m1=int(sys.argv[1]) a) 34 b) 34
m2=int(sys.argv[2]) The multiplied The multiplied value is:
m3=m1*m2 value is: 12 10
print('The multiplied value is: %d' %(m3))
c) 32 d) Syntax Error
a) 3 5 b) 3 5 The multiplied value
The multiplied value The multiplied value is is: 7
is 11 8
72. What will be the output of the following Python
c) 4 3 d) All of these code?
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING

def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)

a) 1 b) 2

c) 3 d) error, there is more


than one return
statement in a single
try-finally block

73. What will be the output of the following Python


code?

def foo():
try:
print(1)
finally:
print(2)
foo()

a) 12 b) 2

c) 3 d) None of these

74. What will be the output of the following Python


code?

from math import factorial


print(math.factorial(5))

a) 20 b) Nothing is printed

c) Error, method d) Error, the statement


factorial doesn’t should be:
exist in math module print(factorial(5))

75. What will be the output of the following Python


expression if X=345?

print(“%06d”%X)

a) 345000 b) 000345

c) 000000345 d) 345000000

You might also like