Part 2 Summary Test

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30
At a glance
Powered by AI
The document appears to be a practice test covering Python essentials topics. It contains 30 multiple choice questions testing concepts like data types, functions, classes, modules and exceptions.

The document is a practice test for a Python essentials course. It contains 30 multiple choice questions and is testing the learner's understanding of core Python concepts.

Try/except blocks in Python are used to catch and handle exceptions. The try block contains code that might raise exceptions, and the except blocks specify handlers for different exception types that will be executed if an exception occurs.

PYTHON

Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 1/30

prints 1.3
The following code:

print (float {" 1.3,T) )


prints 13

prints l, 3

raises a valueError exception

Next 4

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 2/30

has no effect
The following statement:

a33ert var !— 0
wifi stop the program when var = o

is erroneous

will stop the program when var ! = 0

Next 4

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L rV-T-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 3/30

it wit] cause an error


What will be the output of the following snippet?

try:
raise Exception b
except:
print fc")
except Base Except ion:
a
print {"a")
except Exception:
print rb")

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 4/30

it will print 2
What will be the result of executing the following code?

try:
it will print 3
rai3e Except icn (lj, 2r 3}
except .Exception as e:
print {len(e . aigs) J

it will raise an unhandled exception

it wifi print l

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 5/30

one character from the stream


If 2 is a stream opened in read mode, the following line:

q = 3. read (1)
one buffer from the stream

will read:

one line from the stream

one kilobyte from the stream

Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 6/30

It witl print True


What will be the result of executing the following code?

clas3 A:
def {self) : it will print False
pa33

a F A(l}
print (ha3attr {a, 'A1)) it will raise an exception

it wifi print l

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 7/30

it wit] print *
What will be the result of executing the following code?

def o (p):
def q<> : it will print
1 1 ■
return * P
return q

r = 0(1} it witi print **


a = 0(2}
print (r() + 3 ())

it will print

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 8/30

entity c from module b from package a


The following statement:

from a.b import c


entity c from module a from package b

causes the import of:

entity b from module a from package c

entity a from module b from package c

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L rV-T-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 9/30

What will be the output of the following snippet?


o
try:
rai3e Exception b
except 3a3eException:
print {"a")
except Exception:
print {"b") 1
except :
print re")

it will cause an error

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test

Progress (100%)

item 10/30

a null device
The sys.Btderr stream is normally associated with:

the screen

the printer

the keyboard

Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 11/30

it will raise an exception


What will be the result of executing the following code?

clas3 A:
pd33
it wifi print l

clas3 E (A) :
pa33
it will print False
clas3 C (B) :
pa33

print (i3 subclass {A, C) } it wifi print Frue

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 12/30

it wit] print
What will be the result of executing the following code?

def I(n):
3 — T
+' it will print +
for i in range (n):
3 += 3

yield 3
it witi print +++
for x in I(2):
I
1

prints, end= }

it will print ++

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 13/30

the readbytes () method


If you want to fill a byte array with data read in from a stream, you can use:

the readfrom ( ) method

the readinto() method

the read() method

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 14/30

it will raise an exception


What will be the result of executing the following code?

clas3 A:
def a {self) : it wifi print a

print ('a')

da 33 E:
def a {self) : it witl print c

print (,b')

clas3 C ( Bf A): it wifi print b


def c {self) :
self .a{)

Next
o = C()
o.c() *
Retake Test Back to Summary
PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 15/30

it will print 210


What will be the result of executing the following code?

clas3 r :
def _ init _ {self) :
it will print cba
self. 3 = 1
abc 1
self . i = 0
def iter {self) :
return 3elf it will print abc
def next {self) :
if 3elf.i = len(self.s):
raise Stcplteration
v = self .s [self.i] it will print 012
self.i += 1
return v

for x in I { ) : *Prev Next*


I T
print {x, end: )

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 16/30

_P-PY_
What will be the output of the following code, located in the p.py file?

print ( name .)
p.py

main

o main

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test

Progress (100%)

item 17/30

prints 3
The following code:

x = "WW"
print (len{x)) will cause an error

prints l

prints 3

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 18/30

it wifi raise an AttributeErrcr exception


What will be the effect of runni ng the follow!ng code?

clas3 A:
def {3elf , v): it will print 2
self. a - v + 1

a Ff A(0)
print (a . _ a) it wit! print l

it will print o

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L rV-T-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 19/30

mod:fun(}
Knowing that a function named fun[) resides in a module named mod and was
r

imported using the following statement:

from mod import fun 0 funf)

Choose the right way to invoke the fun() function:

mod.fun(}

mod:: fun ()

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 20/30

may be valid if line is a list


The following line of code:

fox line in open {'text .txt T , 1


rt 1 ) :
is valid as open returns an iterable object

is invalid as open returns nothing

is invalid as open returns a non-iterable object

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 21/30

1
What will be the output of the following code?

clas3 A:
A = 1 False
def _ init _ {3elf) :
self. a = 0

print (ha3attr {A, 'a1}) 0

True

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test

Progress (100%)

item 22/30

t
The following code prints:

print (chr {crd {'p') + 2))


q

*Prev Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
C|w !d*rjbm U fV--*: SCJWHTT Ersia
Python Essentials - Part 2 Summary Test

Progress (100%)

item 23/30

prints 1
The following code:

x — "\\\*
print (len{x)) prints 2

prints 3

wifi cause an error

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 24/30

object = Cias3(None)
If the class's constructor is declared as below, which one of the assignments is invalid?

clas3 C 2 a ss :
def {self, val=0): object = Class (1, 2)

pa33

object = Clas3(l)

object = Clas3(J

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 25/30

the number of all the entities residing in the math module


What output wilI appea r after runri ng the foilOWE ng snippet?

import math
print (dir{math)) a list of all the entities residing in the math module

an error message

a string containing the fully qualified name of the module

Next 4

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 26/30

abc
Assuming that the following three files: a.py r b.py.and c.py reside in the same
folder, what will be the output produced after ru nning the c .py file?

bac
# file a, py
print ("a", end— i r )

#f lie b.py
cba
import a
I P
print ("b'\ end: )

#file c.py
print ("c", end='')
import a
o cab

import b

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

item 27/30

What will be the output of the following code?


O 3

clas3 A:
def {self, v=2) : 1
self.v = v

def set {self, v=l) :


self.v += v 0

return self.v

a = A{)
b M a 2

b.a et {)
print (a . v)

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 28/30

py

The compiled Python bytecode is stored in files which have their names ending with:

pc

Q pyc

pyb

Next

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L fV--*:-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 29/30

read the file character by character


Assuming that the open( ) invocation has gone successfully, the following snippet will:

1
for x in open('file', rt 1 ) :
print {x)
read the whole file at once

read the file line by line

cause an exception

Next*

Retake Test Back to Summary


PYTHON
Q INSTITUTE
Gpw Sdjialsii L rV-T-:p*WTr Craa
Python Essentials - Part 2 Summary Test

Progress (100%)

Item 30/30

one or more of the except : blocks will be executed


If there are more than one except: branches after the try: clause, we can say that:

exactly one of the except : blocks will be executed

none of the except: blocks will be executed

not more than one except: block will be executed

41 Prev

Retake Test Back to Summary

You might also like