Total MCQ
Total MCQ
for y in range(3,6)
sum append(x+y)
ans:a
===================================================================
2. which function is used to read two charecters from a file object in file?
a. infile.readline(2)
b.infile.read(2)
c.infile.read()
d.infile.readlines(2)
ans:b
===================================================================
a.dump
b.write
c.output
===================================================================
4.which collection is used to store unique values?
list /dict/tuple/set
ans:set
===================================================================
a.(2,4,6,8)
b.error
c.{4,6}
d.{(2,4),(6,8)}
ans:a
===================================================================
4. class Name(object)
def first(
print("Iam callled")
def second()
obj=Name()
Name.first(obj)
******
a. unbound method call
ans:a
===================================================================
5.which is appropriate to use the static method in a class?
===================================================================
a. tmpfile=askopenfilename()
b.tmpfile=openfilename()
c.tmpfile=saveasfilename()
d.tmpfile=asksaveasfilename()
ans:A
===================================================================
7. def demo():
try;
print(1)
finally;
print(2)
demo()
a.2
b.1 2
c.1
Ans:b
===================================================================
7.on what condition finally block gets executed?
2.on exceptions
3.on errors
4.always
ans:D
===================================================================
b.a user defined exception can be created by deriving a class from error class.
ans:D
===================================================================
9.select the code snippet that divide by zero error with error message " number
cannot be divided with zero"
a. try: 1/except:raise
ans:C
===================================================================
a.1
b. 2 1
c.1 1
Ans:B
===================================================================
y=["test",'Done]
a.['test','done']
b.['TEST','DONE']
d.[None,None]
Ans:a
===================================================================
1.__iter__2 next
b. the iterator next method return the next value for the iterable.
options
--------
a. 1 -a 2 -b
b.***
b.****
d.***
ans:a
===================================================================
13.numbers=[2,4,6,8,1]
print(newnumbers)
a.(4,16,36,64,1)
b.(2,4,6,8,1)
c.[2,4,6,8,1]
d.[4,16,36,64,1]
ans:a
===================================================================
while index>0;
str2 +=str1[index-1]
index=index-1
return str2
print(string_reverse('5678ABCD'))
a.5678ABCD
b.8765DCBA
c.DCBA8765
ans:C
===================================================================
14.which of the following code uses inheritance?
ans:a,c
===================================================================
5.code snippet
class Company:
def__init__(self,name,empnum);
self.name=name
self.empnum=empnum
def myfunc(self);
p1=Company("Cognizant","12345")
a.Welcome to Cognizant
d. Cognizant 12345
ans:C
===================================================================
16. code snippet
def coverFunction();
global a
a=4
def innerFunction();
global a
a=5
print('a=',a)
a=6
coverFunction()
print('a=',a)
a.a=5 a=4
b.a=5
c.a=6
d.a=4
ans:d
===================================================================
17.List the return type of format function on strings
a.boolean
b.string
c.error
d.integer
ans:b
===================================================================
18.true or false
str_variable="Hello Python"
print(str_variable[6:11])
select one
a. true
b.false
Ans:b
===================================================================
a.pass
b.class
c.__init__
d.def
Ans:b
===================================================================
import OrderedDict
my_string1="Welcome 1"
print(my_string1)
my_string3="Welcome 4"
print(my_string3)
my_string4="""Welcome All"""
b. Error
d.Welcome 1 Welcome 2
ans:a
===================================================================
class py_Arraysum
def twoSum(self,numbers,total);
lookup={}
if total-num in lookup;
return(lookup[total-num]+1,i+1)
lookup[num]=i
print("Number1=%d"%py_ArraySum().twoSum((3,1,4,5,2,7),6))
Select one
c. if i, num in enumerate(numbers);
ANS:d
===================================================================
22. Let a tuplevalue contains 5 elements , how to set third element of the tuple to
'india'
a.def test
b.test[3]='india'
c.elements of the tuple remains unchanged
d.test[2]='india'
ans:c
===================================================================
integer=[1,3,4,5,6,7,8,9]
print(integer[::3])
a.[1,3,5,7,9]
b.[1,3,5]
c.[1,3,5,7]
d.[1,4,7]
ans:[1,5,8]
===================================================================
23. sample_dict('n':3,'e':7,'o':9)
sorted(sample_dict)
a.[3,7,9]
b. {'n':3,'e':7,'o':9}
c.{'e':7.'n':3,'o':9}
d.[e,n,o]
Ans:d
===================================================================
b.with statement encapsulates try, except , finally patern for code reuse
d.if an exception occurs in the block __exit__() method of the context manager is
called to clean up resources
ans:a,b,d
===================================================================
def demo():
try:
return 1
finally:
return 3
test=demo()
print(test)
b.3
c.1
Ans:b
===================================================================
if i>2 break
a. true
b.false
ANS:a
===================================================================
30. state the below statements are true or not
python module should contain only definitions like functions,classes and variables
and not statements like print
a. true
b.false
ans:b
===================================================================
31.what is the output of the following
d. i love Apple
Ans:a
===================================================================
32. select the correct statement(check box)
Ans:c,d
===================================================================
33.output for the below code
class Hello:
__init__(self,name)
self.name=name sayHello(self):
print(self.name)
p1=Hello("Tom")
p2=Hello("Sam")
p2.sayHello()
a.Hello Tom
b.Sam
c.Tom
d.Hello Sam
ans:b
===================================================================
34. identify the output
class MapPoint:
def __init__(self,x=0,y=0):
self.x=x+2
self.y=y+3
s1=MapPoint()
print(s1.x,s1.y)
select one
a.error
b.2,3
c.x,y
d.,0
ans:b
===================================================================
ans:a,b
===================================================================
c.print(math pi)
d.print(pi)
ans:b
===================================================================
37. what does the "cycle " function drom "iterators" module do?
a. return a iterator wich cycles through the given list over and over again
a. none object
b.an arbitary object
c.Error function must have a return statement.
ans:a
===================================================================
39. what happens if a non-existant file is opened?
d.raises an exception
ans:d
===================================================================
ans:a
===================================================================
41.select that all applicable to generators(check box)
a.generator help program to perform faster since the code do not wait for the while
data set to be generated.
d. generator yield stament returns one valut at time to the calling loop.
Ans:All
===================================================================
cubes={1,1,28,3:27,4:64,5:125}
print(cubes pop(4))
print(cubes)
a.125{1:1,2:8,3:27,5:125}
b.4{1:1,2:8,3:27,5:125}
c.64{1:1,2:8,3:27,5:125}
ans:c
===================================================================
1.Which action should be avoided so that you do not mistakenly overwrite names that you have
already defined?
2. While using Python IDLE, by how many space are the code suites indented?
3. When using the Python shell and code block, what triggers the interpreter to begin evaluating
block of code?
int
x=flot('inf')
true
true
r'col\tcol2\tcol3\t'
{}
range(20,40,-2)
13. What is the output of below code snippet - for char in 'Welcome': print (char, end='*')
print()
W*e*l*c*o*m*e*
14. What is the output of the following code? for x in (1,10,100): print (x)
1 10 100
16. What is the output of the following code count = 0 while count < 2: print (count, " is less
than 2") count = count + 2 else: print (count, " is not less than 2") - 0 is less than 2; 2 is not less
than 2
18. a = -10 if a: print("a's value") else: print("Sorry nothing will get printed") a's value
20. In what format does the input function read the user input ?
String
21. What is the output of min('Infinity')? I - (Wrong, code output is I but dont know)
False
false
26. Which of the following attributes shows the characteristics of Python? Python is everywhere
(Webscripting, 3D Modelling , Games , and Desktop applications ).
Object Oriented
a-b
0-255
true
31. What command is used to output text from both the Python shell and within a Python
module?
print()
34. The default decode option available in the byte data type is unicode (Wrong answer)
36. Which of these methods can be used with list objects, except ?
decode,Lambda
37. The class which provides immutable sequence of elements tuple
*****************
Attempt 2
******************
1. You can send an email whenever the chef-client fails using ____ handler.
Report
:deleted_cookbook
3. When the success property of the run_status object is true ____handler is executed.
Report
Handlers
test
None of these
7. You can send an email whenever the chef-client fails using ____ handler.
event
8. To generate a new key for the vault use the command _____.
9. Chef maintains a log which has all the users who accessed it.
false
10. To update the content of the vault use the command ______.
Update
11. The chef server has the private part of the RSA key and the nodes/users has the public part
of the key.
false
12. To decrypt an item in the vault and open it in json format use the command _____.
edit
delete
14. The _____ resource from ohai cookbook will help you deploy ohai plugin.
ohai_plugin
false
resolve dependencies
Berkshelf
18. To know what a chef client run would do, use the command _____. Why-run
false
19. Consider a cookbook with name ‘fresco’ and the files within the resource/providers
directory as ‘play’, then the custom resource will be ____.
fresco_play
ohai
21. The process of checking the state of resource collector using ChefSpec is called _______.
Unit Testing
InSpec
23. The _____ object is used to run the report handler without any error handling.
run_report_unsafe
24. To run the knife commands in local mode instead of in server, use the option ____.
-z
Node Object
26. The code to converge the system to desired state will be listed under ______.
providers
27. Use this option in the knife command to specify the files to be added to the vault item.
--file FILE
29. In a custom handler, _____ interface will define how the handler will behave.
30. The process of checking the desired state of the system is called ______.
Integrated Testing
31. The test files in ChefSpec will be place in _____ directory. /spec/unit --------------------------
******************
Puppet 5 - Cardinal
******************
1. Manifest files are stored as ____ file extension.
.pp
false
All of them
while
filter
--noop
before,required
factor -y
No
All
mainifest
14. To see the value of a setting in Puppet, which of the following will you use?
puppet config print
15. You can override modulepath from the commandline using _____. --
modulepath
16. Manifests have logic (conditional statements) and Catalogs (compiled from manifests) do
not have logic.
true
enable
18. _____ function is used to repeat a block of code any number of times.
each
19. You should install Ruby first before installing Puppet-Agent in machines.
No
declarative
21. Which of the following file does Puppet Agent downloads from Puppet Master?
catalog
puppet apply
24. Which of these is the default section in puppet.conf file, which is used by all commands and
services?
main
25. Which of the following is not a Pull based Configuration Management tool? Ansible
26. Puppet compiles catalog from _____. mainifest -- Wrong Answer, May be correct is All the
option
************************
Kibana - Data Exquisites ***************** ******
1. What can be created with the help of Kibana?
Both of these
localhost:5601
5. What is Kibana?
A visulization tool
All of these
geo_point fileds
log
9. Date histogram is performed on date/time values that are automatically extracted from
documents.
true
Documents
11. You can only set the Index pattern once.
false
true
All of these
false
17. What is the function of Gauge? It indecates the status of metric in referance to a threshold
value
Both of these
Yes, we can
21. Anyone in the world can see the visualization with the help of the sharable link.
No, Only those client who have access to Kibana can view
QuestionBaSubBankDifficulty Leve Question Choice 1 Choice 2 Choice 3Choice G
4 radeGrade G
2 rade 3Grade 4
for x in range(0, 20):
print('hello %s' % x)
if x < 9:
Python Flow Control Simple break hello 0 hello 9 hello 1 hello 1 0 0 0
Python Identifiers Simple Which of the following are valid PyPython123 123Python ca$h def 1 0 0 0
Fin the output? >>> 5+4
9
>>> _
9
Python Basics Simple >>> _+15 SyntaxError: in 24 0 9 0 1 0 0
>>> a, _, b = (1, 2, 3)
Python Basics Simple >>> print(a,b) (1,2,3) (1,3) (1,_,2,3) None of the a 0 1 0 0
Find the output for the following
snippet.
_=5
while _ < 10:
print(_, end = ' ')
_ += 1
Python Flow Control Simple 56789 12345 10 9 8 7 6 Error 1 0 0 0
s=input("Enter a string:")
s1=s.replace(' ', '$')
print(s1)
Python Data Strutcure Simple Hello how are yHellohowareyou? Hello$how$are$yo'$' is an inval 0 0 1 0
Identify the output
s=input("Enter a string:")
s1=s[::-1]
print(s1)
Python Data Strutcure Simple n nohtyP yhn nhy 0 1 0 0
a = [1,2,3]
a.append(4,5)
print(a)
Python Data Strutcure Simple Error:append() [1,2,3,4,5] [1,2,3,(4,5)] [4,5,1,2,3] 1 0 0 0
Identify the output
def yrange(n):
i=0
while i < n:
Python Generators Average yield i [1,2,3,4,5] [5,4,3,2,1] [0, 1, 2, 3, 4] None of the a 0 0 1 0
Identify the output
s=input("Enter a string:")
s1=s[::2]
print (s1)
subject1 = [
['Python', 'C++', 'Java'],
['HTML', 'XML', 'JSON']
]
import copy
subject2 =
copy.deepcopy(subject1)
subject2[0][0] = 'Javascript'
Python Deep copy Average print(subject2) [['Javascript', 'C[['Python', 'C++', 'J['Javascript','HTM [['HTML', 'XM 1 0 0 0
Identify the output
Python Function Average a = [10,20,30,40,50] [10, 20, 30, 40 [20, 40, 60, 80, 10Prints nothing [20, 40, 60, 8 0 0 1 0
Find the output for the following
snippet.
class SimpleClass:
def __method1(self):
return "Welcome to Python
Programming"
def call_method2(self):
return self.__method1()
Python Function Difficult AttributeError Welcome to PythoInvalid method ca None of the a 0 1 0 0
Identify the output for the
following code snippet
Python Regular ExpressAverage Which of the following is True abo Checks for a mChecks for a matcChecks all the posChecks all the possible matches in the entire sequence but returns r
Identify the output
list = [[1,2,3],[4,5,6],[7,8,9]]
result=[[row[i] for row in list] for i
in range(2)]
Python Data Structure Difficult print(result) [[1,2,3],[4,5,6]] [[4,5,6],[7,8,9]] [[1, 4, 7], [2, 5, 8]] [[1, 4, 7], [2, 5 0 0 10
Identify the output for the
following snippet.
a=id(tuple[0]) == id(tuple[1])
Python Data Structure Simple print(a) Equal TRUE FALSE None 0 1 0 0
Identify the output for the
following snippet.
a = (1, 1, [3,4])
a.append(5)
Python Data Structure Simple print(a) (1, 1, [3,4],5) (1, 1,5, [3,4]) (5,1, 1, [3,4]) Attribute Erro 0 0 0 1
Identify the output
t1 = (1,2,3,4)
Python Data Structure Simple t2 = [5,6,7,8] (1, 2, 3, 4, 5, 6 can only concaten((1,2,3,4)(5,6,7,8) (1,5,2,6,4,7,4 0 1 0 0
t= (1,)
print(any(t))
Python Data Structure Simple TRUE FALSE 1 0
Identify the type of 'a'
a='1',
Python Data Structure Simple print(type(a)) <class 'tuple'> <class 'str'> <class 'list'> invalid syntax 1 0 0 0
_____method in Python, it is
used to write a list of strings to
Python File Operation Simple the file Writelines() Writes() Write() Writable() 1 0 0 0
which of the following code
makes it useful when we want to
have a string that contains s=a'Hi\nHell
backslash and don’t want it to be s='Hi\nHello' s=r'Hi\nHello' s=b'Hi\nHello' o'
Python Data Structure Average treated as an escape character. print(s) print(s) print(s) print(s) 0 1 0 0
Identify the ouput
def argu(**kwargs):
print(kwargs)
Python Function Average argu(a=10, b=20,c=30) [10,20,30] {'a': 10, 'b': 20, 'c' (10,20,30) {10,20,30} 0 1 0 0
_____method of the os module
in Python, returns a string that
contains the absolute path of the
Python Module Simple current working directory. getcwd() getpwd() getdir() presentdir() 1 0 0 0
Identify the type of module that
provides access to some
variables used or maintained by
the interpreter and to functions
that interact strongly with the
interpreter
Python Module Simple OS module collection module sys module math module 0 0 1 0
Identify the statements True/
False about equality operator
list=[10,0,9,8,3,7,4,6,1,None]
Python list.sort() TypeError [0,1,3,4,6,7,8,9,10[None,0,1,3,4,6,7 [None,0,1,3,4 1 0 0 0
Identify the output
subject=[]
subject.append('Python')
subject.append('Java')
subject.append('C++')
Python Data Structure Average print(subject.pop()) C++ Python Java None of the a 1 0 0 0
Identify the statements True/
False about any(),all()
Python Data Structure Simple The above technique is called Tuple packing Tuple unpacking Tuple assignment None of the a 1 0 0 0
Which of the following is True
Python Function Simple about Range function Only integer ar Parameters can b The range() funct Range functio 1 1 1 0
____is a string literal that occurs
as the first statement in a
module, function, class, or
method definition.
Python Simple docstring __init__ __str__ __name__ 1 0 0 0
class Emp:
def __init__(self, id):
self.id = id
id = 100
a = Emp(123)
Python OOPS Average print (a.id) 100 123 Error None of the a 0 1 0 0
class sample:
def __init__(self):
self.i=10
self.i=i+1
obj=sample()
Python OOPS Average print(a.i) 10 11 0 Error 'i' not d 0 0 0 1
Which of the following technique
is useful if you have edited the
module source file using an
external editor and want to try
out the new version without
Python Module Simple leaving the Python interpreter. reload loadagain refresh clean 1 0 0 0
A function without an explicit
return statement returns
Python Function Simple _______ 1 None 0 Null 0 1 0 0
Which of the following is used to
create a global variable and
make changes to the variable in
Python Identifiers Simple a local context. global local import None of the a 1 0 0 0
In Dictinoary,User is adding
value,If the key is already
available what is the status of
Python Data Structure Simple the old value New entry will bDictionary is immuOld value will be r None of the a 0 0 1 0
Identify the following keyword
which generators uses to return
Python Generators Simple value assign return Yield get 0 0 1 0
Which of the following is called
Python Function Simple as Anonymous function user defined fulambda unknown function null function 0 1 0 0
Python Function Average Identify the types of function Keyword argumPostitional argumeVariable length ar Default argum 0.3 0.3 0.2 0.2
Identify the following function is
used to match a complete target
Python Regular ExpressAverage string. find() searchall() findall() fullmatch() 0 0 0 1
Identify the ouput.
import re
s=re.sub("[a-z]","*","a1b2c3d4e")
Python Regular ExpressDifficult print(s) a*b*c*d*e *a1b2c3d4e* *1234*abcde* *1*2*3*4* 0 0 0 1
class Book:
def __init__(self,id,price):
self.id=id
self.price=price
obj=Book(1,200)
class Book:
def __init__(self,bname,bid):
self.bname=bname
self.bid=bid
1 1 2 2
Python OOPS Difficult print(self.bid) 2 1 1 2 1 0 0 0
Identify how many objects and
reference variables are there in
the below code code?
class A:
print("Welcome to Python")
A()
A()
obj=A()
Python OOPS Difficult obj1=A() 4 and 2 2 and 2 4 and 0 3 and 1 1 0 0 0
t=(10,20,30,40)
a,b,c,d=t
print("a=",a,"b=",b,"c=",c,"d=",d)
This above code technique is
Python Data Structure Simple called? Tuple packing Tuple unpacking Assignment None of the a 0 1 0 0
Which of the following blocks will
be executed whether an
Python Exception Handl Simple exception is thrown or not? catch assert thrown finally 0 0 0 1
What are different types of
inheritance supported by Hierarchical
Python Exception Handl Simple Python? Multiple Inherit Multilevel InheritanInheritance All the above 0 0 0 1
One of the following keryword
performs no action and serves
as a placeholder in Python,it can
be used when a statement is
required syntactically but the
program requires no action
for y in range(3,6)
sum.append(x+y)
2. which function is used to read two charecters from a file object in file?
a. infile.readline(2)
b.infile.read(2)
c.infile.read()
d.infile.readlines(2)
3. which function is used to write the data in the binary format?
a.dump
b.write
c.output
list /dict/tuple/set
a.(2,4,6,8)
b.error
c.{4,6}
d.{(2,4),(6,8)}
4. class Name(object)
def first(
print("Iam callled")
def second()
obj=Name()
Name.first(obj)
**
a. tmpfile=askopenfilename()
b.tmpfile=openfilename()
c.tmpfile=saveasfilename()
d.tmpfile=asksaveasfilename()
7. def demo();
try;
print(1)
finally;
print(2)
demo()
a.2
b.1 2
c.1
2.on exceptions
3.on errors
4.always
b.a user defined exception can be created by deriving a class from error class.
a. try: 1/except:raise
a.1
b. 11 1
c.1 1
11.identify the output
y=["test",'Done]
a.['test','dont']
b.['TEST','DONE']
d.[None,None]
1._iter_2 next
b. the iterator next method return the next value for the iterable.
options
--------
a. 1 -a 2 -b
b.*
b.**
d.*
13.numbers=[,4,6,8,1]
print(newnumbers)
a.(4,16,36,64,1)
b.(2,4,6,8,1)
c.[2,4,6,8,1]
d.[4,16,36,64,1]
14.what is the o/p
while index>0;
str2 +=str1[index-1]
index=index-1
return str2
print(string_reverse('5678ABCD'))
a.5678ABCD
b.8765DCBA
c.DCBA8765
15.code snippet
class Company:
def_init_(self,name,empnum);
self.name=name
self.empnum=empnum
def myfunc(self);
p1=Company("Cognizant","12345")
a.Welcome to Cognizant
d. Cognizant 12345
16. code snippet
def coverFunction();
global a
a=4
def innerFunction();
global a
a=5
print('a=',a)
a=6
coverFunction()
print('a=',a)
a.a=5 a=4
b.a=5
c.a=6
d.a=4
17.List the return type of format function on strings
a.boolean
b.string
c.error
d.integer
18.true or false
str_variable="Hello Python"
print(str_variable[6:11])
select one
a. true
b.false
b.class
c._init_
d.def
import OrderedDict
my_string1="Welcome 1"
print(my_string1)
print(my_string2)
my_string3="Welcome 4"
print(my_string3)
my_string4="""Welcome All"""
a. Welcome 1 Welcome 2 Welcome 4 Welcome All
b. Error
d.Welcome 1 Welcome 2
-------------------------------------
class py_Arraysum
def twoSum(self,numbers,total);
lookup={}
if total-num in lookup;
return(lookup[total-num]+1,i+1)
lookup[num]=i
print("Number1=%d"%py_ArraySum().twoSum((3,1,4,5,2,7),6))
Select one
a. none of the listed
c. if i, num in enumerate(numbers);
22. Let a tuplevalue contains 5 elements , how to se third element of the tuple to 'india'
a.def test
b.test[3]='india'
d.test[2]='india'
integer=[1,2,3,4,5,6,7,8,9]
print(integer[::3])
a.[1,3,5,7,9]
b.[1,3,5]
c.[1,3,5,7]
d.[1,4,7]
23. sample_dict('n':3,'e':7,'o':9)
sorted(sample_dict)
a.[3,7,9]
b. {'n':3,'e':7,'o':9}
c.{'e':7.'n':3,'o':9}
d.[e,n,o]
b.with statement encapsulates try, except , finally patern for code reuse
c. f=open("demo.txt",'f',encoding='utf-8') f.read()
def demo():
try:
return 1
finally:
return 3
test=demo()
print(test)
a.error more than one return statement
b.3
c.1
if i>2 break
a. true
b.false
1.type error
2.value error
3.runtime error
a. raised when the built-in function for a data type has the valid type of arguments, but the
arguments have invalid values specified.
b.raised when an operation or function is atempted that is invalid for the specified data type.
c. raised when a generated error does not fail into any category
select one:
a. .operator
b. operator
a. true b.false
this should be a *
nameFruits('Apple','Mango','orange')
d. i love Apple
class Hello:
_init_(self,name)
self.name=name sayHello(self):
print(self.name)
p1=Hello("Tom")
p2=Hello("Sam")
p2.sayHello()
a.Hello Tom
b.Sam
c.Tom
d.Hello Sam
class MapPoint:
def _init_(self,x=0,y=0):
self.x=x+2
self.y=y+3
s1=MapPoint()
print(s1.x,s1.y)
select one
a.error
b.2,3
c.x,y
d.,0
c.print(math pi)
d.print(pi)
37. what does the "cycle " function drom "iterators" module do?
a. return a iterator wich cycles through the given list over and over again
38. what would be the function return if no return statement is used inside it
a. none object
d.raises an exception
d. generator yield stament returns one valut at time to the calling loop.
cubes={1,1,28,3:27,4:64,5:125}
print(cubes pop(4))
print(cubes)
a.125{1:1,2:8,3:27,5:125}
b.4{1:1,2:8,3:27,5:125}
c.64{1:1,2:8,3:27,5:125}
a.null
b.1
c.none
X=[5,3,6]
a=iter(x)
b=iter(x)
print(next(a))
print(next(b))
a.55
b.12
c.22
d.53
46.
I=sum=0
While i<=5:
Sum+=i
i=i+1
print(sum)
a.1
b.5
c.15
c.4
47. identify the putput
Try:file=open(“demoFile”,”W”)
Excep IOError:
Else:
File.close()
d. File unavailable
48.try:
Pass
Except(TypeError,ZeroDivisionError):
Print(“error”)
b.file is deleted
class hello():
def _repr_(self):
def _str_(self):
say=hello()
print(say)
c.Error
a.unbounded
b.sttatic
c.bounded
d. non-static
Str=”Hello”
Str.center(1,’1’))
b. B.Hello1111
c. 1Hello1111
d. 11Hello11
Class TestClass:
Pass
Test_object=TestClass()
Test_object.attribute=”value”
a.last_object will not becreated due o NameError:name ‘NoObject’ is defined
d. No error
59.python allows functions to be called using keyword arguments and keyword arguments must
follow positinoal arguments
a.true
b.false
Class UserError(“ValueError”):
Pass
class UserError1(UserError):
Pass
Class UserError2(UserError1):
Pass
try:
Prin(“UserError”)
Except UserError1:
print(“UserError1”)
except UserError2
print(“UserError2”)
61.what kind of error do you get while compailing the following code?
Print(Str/2)
a.Zero error
b.type error
d. none error
Import sys
Name=”while rue:
d=sys.stdin.read(1)
if d==”\n”:
break
name=name+d
print “Your comapany is “,name
b.cognizant
Ex_tuple=(‘Python’,)*(a.len_()-a[::-1][])
Print(ex_tuple)
a. (‘Python’)
b. (‘Pyhon’,’Python’)
c. Error
d. 0
fruit_list_1=[‘Orange’,’Gavua’,’Cherry’,’Strawbery’]
fruit_list_2=fruit_list_1
fruit_list1 = ['Apple',
'Berry', 'Cherry',
'Papaya']
fruit_list_3=frui_list_1[:] fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]
fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'
fruit_list_2[]=’Owl’
sum = 0
for ls in (fruit_list1,
fruit_list2, fruit_list3):
fruit_list_3[1]=’Penguin’ if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
sum=0 print (sum)
for ls in (fruit_list_1,frui_list_2,fruit_list_3):
if ls[]==’owl’
sum+=1
if ls[1]==’Penguin’:
sum+=2
print(sum)
a. 21
b. 22
c. 2
a.list_1.remove(“World”)
b.list_1.removeAll(“World”)
c.list_1.removeOne(“World”)
d.list_1.remove(World)
Vowels=[‘a’,’e’,’i’,’o’,’u’]
Print(vowels,3)
a.[ ’o’,’u’]
b. [‘a’,’e’,’i’,’o’,’u’]
c. [‘a’,’e’]
d.[ ’i’,’o’]
Answer: 1
2. which function is used to read two charecters from a file object in file?
a. infile.readline(2)
b.infile.read(2)
c.infile.read()
d.infile.readlines(2)
Answer: b
Answer: a
Answer: d
Answer: b
6. class Name(object)
def first(
print("Iam callled")
def second()
print("i got called")
obj=Name()
Name.first(obj)
**
a. unbound method call
b. bounded method call
c.incorrect object declaration
d.all the above
Answer: c
Answer: c&d
Answer: a
9. def demo();
try:
print(1)
finally:
print(2)
demo()
a.2
b.1 2
c.1
d.1
2
Answer: d
10. On what condition finally block gets executed?
1.on sepecific condition
2.on exceptions
3.on errors
4.always
Answer: 4
Answer: d
12. Select the code snippet that divide by zero error with error message " number cannot be divided
with zero"
a. try: 1/except:raise
b.try: 1/except ax e : print(e)
c. try: 1/ except ZeroDivisionError: print("number cannot be divided with zero")
d.try: 1/ except ValueError: print (("number cannot be divided with zero")
Answer: c
Answer: d
Answer: a
15. Select the correct match
1._iter_
2 next
a.method that is called a initialization of an iterator
b. the iterator next method return the next value for the iterable.
options
--------
a. 1 -a 2 -b
b.*
b.**
d.*
Answer: a
16. Numbers=[2,4,6,8,1]
newnumbers= tuple(map(lamda x:x*x,numbers))
print(newnumbers)
a.(4,16,36,64,1)
b.(2,4,6,8,1)
c.[2,4,6,8,1]
d.[4,16,36,64,1]
Answer: a
Answer: c
Answer: a & c
19. Code snippet
class Company:
def_init_(self,name,empnum);
self.name=name
self.empnum=empnum
def myfunc(self);
print("Welcome to"+self.name+' '+self.empnum)
p1=Company("Cognizant","12345")
a.Welcome to Cognizant
b.Syntax error, this program will not run
c. Welcome to Cognizant 12345
d. Cognizant 12345
Answer: d
Answer: b
22. True or False
output of the below statement is "Python"
str_variable="Hello Python"
print(str_variable[6:11])
select one
a. true
b.false
Answer: b (false)
Answer: b
Likewise,
Answer: d
26. Let a tuple value contains 5 elements , how to se third element of the tuple to 'india'
a.def test
b.test[3]='india'
c.elements of the tuple remains unchanged
d.test[2]='india'
Answer: c
Answer: d
28. Sample_dict={'n':3,'e':7,'o':9}
sorted(sample_dict)
a.[3,7,9]
b. {'n':3,'e':7,'o':9}
c.{'e':7.'n':3,'o':9}
d.[e,n,o]
Answer: d
29. Select the applicable to with statement( check box)
a.with statement is used to loop over a generator
b.with statement encapsulates try, except , finally patern for code reuse
c.with stement is used to alias an object
d.if an exception occurs in the block _exit_() method of the context manager is called to clean up
resources
Answer: A&B&C&D
30. Select the correct option that closes file if exception occurs
a. none of the listed options
b. with open("demo.txt", encoding='utf-8')as f # perform file operations
c. f=open("demo.txt",'f',encoding='utf-8') f.read()
d.try #code that can raise error pass
ANSWER: b
Answer: a
33. Match the statement with correct option
1.type error
2.value error
3.runtime error
a. raised when the built-in function for a data type has the valid type of arguments, but the
arguments have invalid values specified.
b.raised when an operation or function is atempted that is invalid for the specified data type.
c. raised when a generated error does not fail into any category
select one:
a. all of the listed options
b.1-c 2-a 3-b
c.1-a 2-b 3-c
d. 1-b 2-a 3-c
Answer: d
Answer: a
Answer: b (false)
Answer: c & d
Answer: b
Answer: b
40. Select the correct statement
choose one or two
a.tuple is immutable and list is mutable
b.set is an unordered collection of unique items
c.Dictinoary is an ordered collection of key-value pairs
d.tuple is mutable and list is immutable
Answer: a & b
Answer: b
42. What does the "cycle " function from "iterators" module do?
a. return a iterator wich cycles through the given list over and over again
b. returns a iterator for the given iteratable object
c.converts the given list into generator
d. cycles through the given list
Answer: a
43. What would be the function return if no return statement is used inside it
a. none object
b.an arbitary object
c.Error function must have a return statement.
Answer: a (if any return statement is not mentioned I a function, “None” is returned)
Answer: d
45. Select the correct option
a. custom exception is unavailable in python
b. a user-defined exception can be created by deriving a class from exception class
c. none of the listed options
d. a user-defined exception can be deriving a class from error class
Answer: b
Answer: a,c,d
B (generator is not only used to loop over list)
Answer: c
Answer: a,c,d
b -> correct -> if only single object not mentioned
(Operator overloading: operator behaves differently when used with operands of different data
types)
Answer: a (55)
Answer: c
Answer: c
53. try:
Pass
Except(TypeError,ZeroDivisionError):
Print(“error”)
a. If no execpion occurs,print error
b. Always prin error
c. If TypeError or ZeroDivisionError occurs,prints Error
d. If any Exception(other than TypeError, ZeroDivisionError occurs,prints Error
Answer: c
54. What will be the result if the file is opened in ‘a’ mode?
a. opens a file for appending at the end of the file.
b. file is deleted
c. file is opened for reading only
d. file is opened for writing
Answer: a
Answer: d
Answer: a
57. The class methods in python
a. unbounded
b. static
c. bounded
d. non-static
Answer: a
Answer: a
Answer: b