Francis Xavier Engineering College: (Autonomous)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)

COMMON ASSESSMENT TEST -2


ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
a) keyword parameter b) variable length
1. Which of the following Python code will give parameter
different output from the others?
c) default parameter d) None of the above
a) for i in range(0,5): b) for j in [0,1,2,3,4]:
print(i) print(j) 9. A variable with a local scope can be used

c) for k in d) for l in range(0,5,1): a) only within the b) outside the function


[0,1,2,3,4,5]: print(l) function
print(k)
c) none of these d) Both A and B
2. Which of the following is a valid for loop in Python?
10. _____is defined as sequence of characters
a) for(i=0; i < n; i++) b) for i in range(0,5): represented in quotation marks (either single
quotes ( ‘ ) or double quotes ( “ ).
c) for i in range(0,5) d) for i in range(5)
a) Characters b) String
3. A while loop in Python is used for what type of
iteration? c) Integers d) None of these

a) indefinite b) discriminant 11. ______ can be written as a list of comma-


separated items (values) between square
c) definite d) indeterminate brackets[].

4. When does the else statement written after loop a) List b) Array
executes?
c) Tuple d) None of these
a) When break b) When loop condition
statement is becomes false 12. Identify the operations in List
executed in the loop
a) Indexing b) Slicing
c) Else statement is d) None of the above
always executed c) Concatenation d) All of these

5. Identify the keyword for pass statement 13. What is the purpose of slicing?

a) passs b) pass a) Printing a part of b) Adding and printing


the list. the items of two lists.
c) pas d) None of these
c) Create a multiple d) All of these
6. A function that returns a value is called_____ copies of the same
list.
a) User-defined b) fruitful function.
function 14. _____ operation extracts a subset of elements from
an list and packages them as another list.
c) None of these d) Both A and B
a) Concatenation b) List Slicing
7. Code that appears after a return statement, or any
other place the flow of execution can never reach, c) append d) All of these
is called ____
15. The method that adds an element to the end of the
a) Void b) Static list

c) Dead Code d) None of these a) a.extend(b) b) a.append(element)

8. Python allows function parameter to have default c) a.copy() d) None of these


values; if the function is called without the
argument, the argument gets its default value in 16. Identify the method to add all elements of a list to
the function definition the another list.
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
a) a.extend(b) b) Add(b) 25. ______ often useful to swap the values of two
variables.
c) Both A and B d) None of these
a) Array b) List
17. Identify the method that returns the index of the
first matched item c) Tuple Assignment d) None of these

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. Creating a copy of a list is called ____ c) Both a and b d) None of these

a) aliasing b) copying 29. The method used to add the dictionary with the
existing dictionary
c) listing d) None of these
a) a.update(dictionar b) edit(Dictionary)
21. _____is a process of making a copy of the list y)
without modifying the original list.
c) Change(dictionary) d) None of these
a) Aliasing b) copying
30. _______provide a concise way to apply operations
c) Cloning d) All of these on a list.

22. Passing a list as an argument actually passes a a) Dictionary b) Tuple


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

a) Mutable list b) An immutable list


c) infile = open(file = d) infile = open(file =
c) Changeable d) None of these “c:\scores.txt”, “r”) “c:\\scores.txt”, “r”)

24. ______can be used as keys in dictionaries 32. Identify the features of Text files

a) List b) Tuples a) Human-readable b) File processed using


text editor
c) Both d) None of these
c) Structured as a d) All of these
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
sequence of (syntax) of the language is called
characters
a) Exception(Runtime b) syntax error or
33. A _____is a sequence of characters stored on a errors) parsing error.
permanent medium like a hard drive, flash memory,
or CD-ROM. c) Both a and b d) None of these

a) textfile b) Binary file 41. Errors can also occur at runtime and these are
called ____
c) Readable file d) All of these
a) exceptions b) Syntax error
34. Overwrite the contents of file with new contents by
opening a file using ____ c) semantic error d) None of these

a) Read mode b) Append mode 42. Identify the possible exceptions at runtime

c) write mode d) None of these a) when a file we try to b) dividing a number by


open does not exist zero
35. Which of the following statements are true? (FileNotFoundError) (ZeroDivisionError)

a) When you open a file b) When you open a file c) module we try to d) All of these
for reading, if the for writing, if the file import is not found
file does not exist, does not exist, a new (ImportError)
an error occurs file is created
43. Python exception that Raised when attribute
c) When you open a file d) All of these assignment or reference fails
for writing, if the file
exists, the existing a) AttributeError b) FloatingPointError
file is overwritten
with the new file c) ImportError d) IndexError

36. Identify to function to determine whether a file 44. ____is a file containing Python definitions and
exists. statements

a) isfile() b) Is.file() a) A file b) A data

c) Fileexist() d) Is.fileexist() c) A module d) All of these

37. Identify the module used for command line 45. Identify the python modules
arguments
a) random b) Decimal
a) system b) cons
c) Htmal.parser d) All of these
c) sys d) All of these
46. _____is a collection of modules
38. ____is any issue that arises unexpectedly that
causes a computer to not function properly. a) A package b) Nested module

a) A mistake b) A fault
c) files d) All of these

c) An error d) All of these 47. The main difference between a module and a
package is that a package is
39. Identify the basic errors
a) A collection of files b) Collection of modules
a) Syntax error(parsing b) Exception(Runtime
errors) errors)
c) A collection of d) All of these
modules AND it has
c) Both a and b d) None of these an __init__.py file.

40. Error caused by not following the proper structure 48. Identify the format operstor
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
a) % b) = a) a result tuple b) a result dictionary

c) * d) + c) a result list d) None of these

49 It is a process that enables a program to deal with 56. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is
the exceptions and continue its normal execution. len(listExample)?

a) Identifying the error b) handling exception a) 5 b) 4

c) Both a and b d) None of these c) Error d) None

50. Python Exception that Raised when the imported 57. Suppose list1 is [1, 5, 9], what is sum(list1)?
module is not found
a) 1 b) 9
a) FloatingPointError b) EOFError
c) 15 d) None of these
c) ImportError d) All the these
58. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the
51. What will be the output of the following Python following is correct syntax for slicing operation?
code?
for i in range(0,2,-1): a) print(list1[0]) b) print(list1[:2])
print("Hello")
Note: Q.No 51 to 75 Carries 2 Marks c) print(list1[:-2]) d) All the mentioned

a) Hello b) Hello Hello 59. What will be the output of the following
c) No Output d) Error Python code

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


>>>t=(1,2,4,3)
Which of the following sequences would be
generated be the given line of code?
x="abcdef" >>>t[1:-1]
i="i"
while i in x:
print(i,end="")
a) (1, 2) b) (1,2,4)
a) abcdef b) abcdef
c) (2,4) d) (2,4,3)
c) i i i i i..... d) No Output
60. What will be the output of the following Python
53. What will be the output of the following code? code?
x="abcd"
for i in range(len(x)): >>>t = (1, 2, 4, 3, 8, 9)
print(i) >>>[t[i] for i in range(0, len(t), 2)]

a) abcd b) 0123 a) [2, 3, 9] b) [1, 2, 4, 3, 8, 9]

c) 1234 d) abcd c) [1, 4, 8] d) (1, 4, 8)

54. What will be the output of the following code? 61. What will be the output of the following Python
x=5 code?
for i in x: >>>t = (1, 2)
print(i) >>>2 * t

a) 12 b) 12 a) (1, 2, 1, 2) b) [1, 2, 1, 2]

c) Error d) None of the above c) (1, 1, 2, 2) d) [1, 1, 2, 2]

55. The list comprehension always returns _____ 62. What will be the output of the following Python
code snippet?
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
d1 = {"john":40, "peter":45} a) Bracket is missing b) No error
d2 = {"john":466, "peter":45}
d1 > d2 c) a colon is missing d) None of these
in the if statement
a) True b) False
68. What will be the output of the following Python
c) Error d) None code?

63. Suppose d = {“john”:40, “peter”:45}. To obtain the f = None


number of entries in dictionary which command do for i in range (5):
we use? with open("data.txt", "w") as f:
if i > 2:
a) d.size() b) len(d) break
print(f.closed)
c) size(d) d) d.len()
a) True b) False
64. What will be the output of the following Python
code snippet? c) None d) Error

d = {"john":40, "peter":45} 69. To read the next line of the file from a file object
print(list(d.keys())) infile, we use ____________

a) [“john”, “peter”] b) [“john”:40, “peter”:45] a) infile.read(2) b) infile.read()

c) infile.readline() d) infile.readlines()
c) (“john”, “peter”) d) (“john”:40, “peter”:45)
70. Find the output of this code
65. Suppose d = {“john”:40, “peter”:45}, what print(“We are using python %d version”%(3))
happens when we try to retrieve a value using the
expression d[“susan”]? a) We are using b) We are using python
python 3 version %d version
a) Since “susan” is not b) It is executed fine and
a value in the set, no exception is raised, c) We are using d) None of these
Python raises a and it returns None python3version3
KeyError exception
71. Find the output of the following program
c) Since “susan” is d) Since “susan” is not a import sys
not a key in the key in the set, Python m1=int(sys.argv[1])
set, Python raises raises a syntax error m2=int(sys.argv[2])
a KeyError m3=m1*m2
exception print('The multiplied value is: %d' %(m3))

66. Find the output of the program a) 34 b) 34


import sys The multiplied The multiplied value is:
m1=int(sys.argv[1]) value is: 12 10
m2=int(sys.argv[2])
m3=m1*m2 c) 32 d) Syntax Error
print('The multiplied value is: %d' %(m3)) The multiplied value
is: 7
a) 3 5 b) 3 5
The multiplied value The multiplied value is 72. What will be the output of the following Python
is 11 8 code?

c) 4 3 d) All of these def foo():


The multiplied try:
value is 12 return 1
finally:
67. Identify the error in the following code return 2
>>> if a < 3 k = foo()
>>>print(a) print(k)
FRANCIS XAVIER ENGINEERING COLLEGE (AUTONOMOUS)
COMMON ASSESSMENT TEST -2
ODD SEMESTER 20-21
COURSE: 19CS1501 PYTHON PROGRAMMING
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


code?

#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)

a) [2,4,6] b) [1,4,9]

c) [2,4,6] d) There is a name


[1,4,9] clash

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy