What is the output of the code shown below?
#generator
def f(x):
yield x+1
g=f(8)
print(next(g))
8
9
7
Error
SHOW ANSWERWhat is the output of the following code?
def a():
try:
f(x,4)
finally:
print('after f')
print('after f?')
a()
error
after f?
after f
error
after f
SHOW ANSWERWhich of the following blocks will be executed whether an exception is thrown or not?
except
else
finally
assert
SHOW ANSWERWhat is the output of the following program:
y=8
z= lambda x:x*y
print z(6)
48
14
64
none of the above
SHOW ANSWERWhich of the following statement is true?
You cannot create custom exceptions in Python
You can create a user-defined exception by deriving a class from Exception class
You can create a user-defined exception by deriving a class from Error class
None of the above.
SHOW ANSWERWhich of the following is correct?
An exception is an error that occurs at the runtime.
A syntax error is also an exception.
An exception is used to exclude a block of code in Python.
All of the above.
SHOW ANSWERWhat is the output of the following code?
number = 5.0
try:
r= 10/number
print(r)
except:
print("Oops! Error occurred.")
Oops! Error occurred.
2.0
2.0 Oops! Error occurred.
None object
SHOW ANSWERWhat does the following code do?
try:
# code that can raise error
pass
except (TypeError, Zero DivisionError):
print("Two")
Prints Two if exception occurs (doesn't matter which exception).
Prints Two if exception doesn't occur.
Prints Two if TypeError or Zero DivisionError exception occurs.
Prints Two only if both TypeError and Zero Division Error exception occurs.
Prints Two only if both
SHOW ANSWERWhat does os.name contain?
the name of the operating system dependent module imported
the address of the module os
error, it should've been os.name()
none of the mentioned
SHOW ANSWERWhat does os.getlogin() return?
a name of the current user logged in
name of the superuser
gets a form to login as a different user
all of the above
SHOW ANSWERWhich of the following functions can be used to read data from a file using a file descriptor?
os.reader()
os.read()
os.quick_read()
os.scan()
SHOW ANSWERWhich of the following can be used to create a directory?
os.mkdir()
os.creat_dir()
os.create_dir()
os.make_dir()
SHOW ANSWERWhich of the following returns a string that represents the present working directory?
os.getcwd()
os.cwd()
os.getpwd()
os.pwd()
SHOW ANSWER