Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Online Training Exam Details

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

12/26/22, 3:58 PM PSIT

Home (https://erp.psit.ac.in/Erp/) / Student (https://erp.psit.ac.in/Student) / Online Training Exam Details

Online Training Exam Details

Online Training Exam Details    

S.no Attempt Answer Correct Answer Status

1 B B

What is the output of the following code snippet?

sample_dict={'a':1,'b':2}
sample_dict.update({'b':5, 'c':10 })
print(sample_dict.get('a'),sample_dict.get('b'),sample_dict.get('c'))

a) None 5 10

b) 1 5 10

c) 1 2 None

d) 1 5 None

2 B B

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 1/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What is the output of the code given below?

message="welcome to Mysore"
word=message[-7:]
if(word=="mysore"):
print("got it")
else:
message=message[3:14]
print(message)

a) got it

b) come to Mys

c) come to Myso

d) lcome to Mys

3 D D

What is the output of the code shown below?


g = (i for i in range(5))
type(g)
a) class <’loop’>
b) class <‘iteration’>
c) class <’range’>
d) class <’generator’>

4 C C

What is the output of the code shown below?


def getMonth(m):
if m<1 or m>12:
raise ValueError("Invalid")
print(m)
getMonth(6)
a) ValueError
b) Invalid
c) 6
d) ValueError(“Invalid”)

5 A A

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 2/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What is the output of the code shown?


def f(x):
for i in range(5):
yield i
g=f(8)
print(list(g))
a) [0, 1, 2, 3, 4]
b) [1, 2, 3, 4, 5, 6, 7, 8]
c) [1, 2, 3, 4, 5]
d) [0, 1, 2, 3, 4, 5, 6, 7]

6 B B

import itertools
l1=(1, 2, 3)
l2=[4, 5, 6]
l=itertools.chain(l1, l2)
print(next(l1))
a) ‘list’ object is not iterator
b) ‘tuple’ object is not iterator
c) ‘list’ object is iterator
d) ‘tuple’ object is iterator

7 C C

What is the output of the following code?


def a():
try:
(x, 4)
finally:
print('after f')
print('after f?')
a()
a) No output
b) after f?
c) after f then Name error
d) after f

8 B B

What is the output of the code shown below?


def f(x):
yield x+1
g=f(8)
print(next(g))
a) 8
b) 9
c) 7
d) Error

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 3/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

9 D D

What is the output of the code shown below?


def f(x):
yield x+1
print("test")
yield x+2
g=f(9)
a) Error
b) test
c) test and 10 and 12
d) No output

10 A A

What is the output of the following code?


def foo():
try:
print(1)
finally:
print(2)
foo()
a) 1 2 b) 1 c) 2 d) none of the mentioned

11 A A

What is the output of the following code ?

a = 20
b = 30
assert b - a , 'a is smaller than b'
print(b)
a)30
b)20
c)10
d)Assertion Error:a is smaller than b

12 A A

Can one block of except statements handle multiple exception?


a) yes, like except TypeError, SyntaxError [,…].
b) yes, like except [TypeError, SyntaxError].
c) no
d) none of the mentioned

13 B B

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 4/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What is the output of the following code?


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

14 A A

What is the output of the following code ?

try:
if '2' != 2:
raise ValueError
else:
print('same')
except ValueError:
print('ValueError')
except NameError:
print('NameError')
a)Value Error
b)Name Error
c)same
d)None of the above

15 D D

What is the output of the following code ?

try:
print('try')
except ValueError:
print('ValueError')
finally:
print('finally')
a)try
b)finally
c)Value Error
d)try finally

16 B B

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 5/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What is the difference between 'r+' and 'a' modes?


A. no difference
B. in 'r+' the pointer is initially placed at the beginning of the file and the pointer is at the end for 'a'
C. in 'w+' the pointer is initially placed at the beginning of the file and the pointer is at the end for 'r+'
D. depends on the operating system

17 C C

When will the else part of try-except-else be executed?


a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block

18 D D

Is the following code valid?


try:
# Do something
except:
# Do something
finally:
# Do something
a) no, there is no such thing as finally
b) no, finally cannot be used with except
c) no, finally must come before except
d) yes

19 B B

What is the output of the following code?


string = "This is python"
id1 = id(string)
string = string.replace("python", "java")
id2 = id(string)
print (id1 == id2)
A. True
B. False
C. 0
D. 1

20 B B

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 6/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What will be the output of the following code?


string = "This is python test"
string.replace("python", "perl")
print (string)

A. This is perl test


B. This is python test
C. 'str' object is immutable
D. None of the above

21 A A

Predict the output of following Python Program


count = 1

def doThis():

global count

for i in (1, 2, 3):


count += 1

doThis()

print (count)
A)4
B)3
C)2
D)0

22 C C

dictionary = {1:'1', 2:'2', 3:'3'}


del dictionary[1]
dictionary[1] = '10'
del dictionary[2]
print (len(dictionary))
A)4
B)3
C)2
D)0

23 D D

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 7/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What will the output of the following line?


>>>"PYTHON TEST"[-11:-1:-1]

A. >>>'TSET NOHTY'
B.>>> 'PYTHON TES'
C.>>> PYTHON TEST
D.None of the above

24 A A

Predict the output of following Python Programs.


counter = {}

def addToCounter(country):
if country in counter:
counter[country] += 1
else:
counter[country] = 1

addToCounter('China')
addToCounter('Japan')
addToCounter('china')

print (len(counter))
A)3
B)2
C)1
D)0

25 A A

What will be the output of the following code?


string = "12345678"
s = ""
for i in range(len(string)):
s = string[i] + s
print (s)

A. 87654321
B. 12345678
C. NameError
D. TypeError

26 C C

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 8/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

print (('hello' + 'world') + ('how are you?') * 0)

A. Error
B. prints nothing
C. helloworld
D. 0

27 B B

What will be printed from the following code?


string = "PYTHON TEST"
for i in string:
if i == "N":
pass
print (i, end = "")

A. PYTHO TEST
B. PYTHON TEST
C. PYTHONTEST
D. Error

28 C C

What Will Be The Output Of The Following Code Snippet?


colors = ['red ', 'yellow ', 'blue ']
f = open('colors.txt', 'w')
f.write(colors)
f.seek(0,0)
for line in f:
print (line)
f.close()
A. red
yellow
blue
B. [‘red ’, ‘yellow ’, ‘blue ’]
C. Error
D. Compilation error

29 B B

What is the output of the following code?


string = "65 66 67 68 69 70 71"
for i in string:
print (chr(i), end = " ")
A. ABCDEFG
B. Error
C. acdefg
D. None of the above

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af546671… 9/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

30 A A

Assuming that there is a file 'data.txt' in current directory, what will be the output of the following Python code?
f = None
for i in range(5):
if i > 2:
break

with open("data.txt", "r") as f:


print(f.read())

f.close()
A. Entire contents of the file are displayed
B. Only two lines of the file are displayed
C. Only 3 lines of the file are displayed
D. Error

31 A A

What Will Be The Output Of The Following Code Snippet?


fo = open("myfile.txt", "r") # there is a file myfile.txt
fo.seek(10)
print ("Contents: ", fo.read())
fo.close()
A. first 10 characters of the file are skipped and rest are displayed
B. first 10 characters are displayed
C. first 10 lines are skipped
D. Syntax Error

32 A A

What Will Be The Output Of The Following Code Snippet?


fo = open("myfile.txt", "w")
fo.writelines(12460)
fo.close()

A. TypeError
B. myfile.txt now contains "12460"
C. myfile.txt now contains 12460
D. gives warning and writes the content

33 C C

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af54667… 10/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What Will Be The Output Of The Following Code Snippet?


with open("hello.txt", "w") as f:
f.write("Hello World how are you today")

with open('hello.txt', 'r') as f:


data = f.read()
for line in data:
words = line.split()
print (words)
f.close()

A. Runtime Error
B. Hello World how are you today
C. returns a list of one character on each line
D. Hello

34 C C

What Will Be The Output Of The Following Code Snippet?


f = open("data.txt", "w")
txt = "This is 1st line "
f.writelines(txt, list)
f.seek(0,0)
line = f.readlines()
print ("Read Line: %s" % (line))
f.close()

A. ['This', 'is', '1st', 'line’]


B. []
C. Error
D. None

35 D D

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af54667… 11/12
12/26/22, 3:58 PM PSIT

S.no Attempt Answer Correct Answer Status

What Will Be The Output Of The Following Code Snippet?


try:
f = open("testfile", "r")
f.write("This is the test file for exception handling!!")
except IOError:
print ("Error: could not find a file or read data")
finally:
print ("In finally part")
else:
print ("content is written in the file successfully")

A. This is the test file for exception handling!!


In finally part
B. Error: could not find a file or read data
In finally part
C. In finally part
content is written in the file successfully
D. SyntaxError

https://erp.psit.ac.in/Student/OnlineTrainingDetails/3f3a8af563d88b40a2f41b94851029ad9493d85c6d7d25515233b6717cde34c2633b2920af54667… 12/12

You might also like