My Report

Python Exception Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. The error displayed in the following Python code is?

import itertools
l1=(1, 2, 3)
l2=[4, 5, 6]
l=itertools.chain(l1, l2)
print(next(l1))

2. What will be the output of the following Python code?

def a():
    try:
        f(x, 4)
    finally:
        print('after f')
    print('after f?')
a()

3. What will be the output of the following Python code?

def f(x):
    for i in range(5):
        yield i
g=f(8)
print(list(g))

4. Which of the following is not an exception handling keyword in Python?

5. What will be the output of the following Python code?

x=10
y=8
assert x>y, 'X too small'

6. What will be the output of the following Python code?

def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(10)
print(next(g))
print(next(g))

7. What will be the output of the following Python code?

#generator
def f(x):
    yield x+1
g=f(8)
print(next(g))

8. The following Python code will result in an error if the input value is entered as -5.

assert False, 'Spanish'

9. What will be the output of the following Python code?

def f(x):
    yield x+1
    print("test")
    yield x+2
g=f(9)

10. What will be the output of the following Python code?

g = (i for i in range(5))
type(g)

 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.