You are on page 1of 2

Sr no Question A B C D Answer

1 What will be the output of print(10,20,30,sep="/") 10 20 30 10/20/30 10\20\30 Error B


What will be the output of print("{0} is a diploma {0} is a diploma 0 is a diploma VESP is a
2 Error D
portal",format("VESP")) portal portal diploma portal
infile = open(file
infile = . infile = infile = open(file
Which of the following command is used to open a file “c:\temp.txt” in = “c:\temp.txt”,
3 open(“c:\temp.txt open(“c:\\temp.tx = “c:\\temp.txt”, B
read-mode only? “r+”)
”, “r”) t”, “r”) “r+”)
outfile = . outfile =
outfile = outfile =
Which of the following command is used to open a file “c:\temp.txt” in open(file = open(file =
4 open(“c:\temp.txt open(“c:\\temp.tx B
write-mode only? “c:\temp.txt”, “c:\\temp.txt”,
”, “w”) t”, “w”)
“w+”) “w+”)
outfile = outfile = outfile = outfile =
which of the following command is used to open a file “c:\temp.txt” in
5 open(“c:\\temp.tx open(“c:\\temp.tx open(“c:\temp.txt open(“c:\temp.txt Answer
append-mode?
t”, “a”) t”, “rw”) ”, “w+”) ”, “w+”)
Which of the following commands can be used to read “n” number of file.readlines()
6 file.read(n) n = file.read() file.readline(n) A
characters from a file using the file object ?
Which of the following commands can be used to read the next line in
7 tmpfile.read(n) tmpfile.read() tmpfile.readlines C
a file using the file object <tmpfile>? tmpfile.readline()
()
8 What does the <readlines()> method returns? str a list of lines single character list of integer B
9 How many except statements can a try-except block have? zero one more than one more than zero D
when an
when exception when no exception occurs
10 When will the else part of the try-except-else be executed? always C
occurs exception occurs in to except
block
Is the following Python code valid? try:
#statements
no, there is no no, else cannot no, else must
except:
11 such thing as be used with come before yes D
#statements
else except except
else:
#statements
only if some
condition that
when there is no when there is an
12 When is the finally block executed? has been always D
exception exception
specified is
satisfied
What will be the output of the following Python code?
def fun():
try:
return 1
13 1 2 3 Error B
finally:
return 2
obj=fun()
print(obj)
What will be the output of the following Python code?
def fun():
try:
14 print(1) 1 2 12 None C
finally:
print(2)
fun()
What will be the output of the following Python code?
try:
a=10
b=5
c=a/b
2.0 2.0
print(c) 2.0 2.0
15 NO ERROR ERROR A
except: END NO ERROR
END END
print("ERROR")
else:
print("NO ERROR")
finally:
print("END")
What will be the output of the following Python code?
try:
a=10
b=0
c=a/b
2.0 2.0
print(c) ERROR 2.0
16 NO ERROR ERROR C
except: END NO ERROR
END END
print("ERROR")
else:
print("NO ERROR")
finally:
print("END")
What will be the output of the following Python code?
try:
a=10
b=0
17 Error 10 Name Error division by zero D
c=a/b
print(c)
except(NameError,ZeroDivisionError) as obj:
print(obj)
What will be the output of the following Python code?
try:
a=10
b=5
18 0 10 5 Error C
c=a/b
print(c)
except(NameError,ZeroDivisionError) as obj:
print(obj)
What will be the output of the following Python code?
try:
a=10
b=2 name 'g' is not
19 Error 10 division by zero C
c=a/g defined
print(c)
except(NameError,ZeroDivisionError) as obj:
print(obj)
What will be the output of the following Python code?
try:
a=10
b=2 name 'g' is not
20 Error 10 division by zero A
c=a/g defined
print(c)
except(NameError,ZeroDivisionError):
print("ERROR")

You might also like