Python Essentials 2: INTERMEDIATE


Module-2


                   

1 - The following code: print(ord('c') - ord('a'))
a) 0
b) 2
c) 3
d) 1
Solution: b

2 - The following code: print (float("1, 3" ))
a) prints 1, 3
b) raises a ValueError exception
c) prints 1.3
d) prints 13
Solution: b

3 - The top-most Python exception is called:
a) TopException
b) Exception
c) BaseException
d) PythonException
Solution: c

4 - The following statement: assert var == 0
a) is erroneous
b) will stop the program when var != 0
c) has no effect
d) will stop the program when var == 0
Solution: b

5 - UNICODE is a standard:
a) used by coders from universities
b) honored by the whole universe
c) like ASCII, but much more expansive
d) for coding floating-point numbers
Solution: c

ASCII is:

a) a predefined Python variable name
b) a standard Python module name
c) a character name
d) short for American Standard Code for Information Interchange
Solution: d

7 - The following code: print(3 * 'abc' +'xyz') prints:

a) xyzxyzxyzxyz
b) abcabcxyzxyz
c) abcabcabcxyz
d) abcxyzxyzxyz
Solution: c

8 - UTF-8 is:

a) a Python version name
b) the 9th version of the UTF standard
c) a form of encoding Unicode code points
d) a synonym for byte
Solution: c

9 - Entering the try: block implies that:
a) all of the instructions from this block will be executed
b) some of the instructions from this block may not be executed
c) the block will be omitted
d) none of the instructions from this block will be executed
Solution: b

10 - What is the expected output of the following code? try print("5"/0) except ArithmeticError: print("arith") except ZeroDivisionError: print("zero") except: print("some")
a) zero
b) 0
c) some
d) arith
Solution: c

11 - The unnamed except: block:
a) must be the first one
b) can be placed anywhere
c) cannot be used if any named block has been used
d) must be the last one
Solution: d

12 - The following code:
print('Mike' > " Mikey") prints: a) 0
b) 1
c) True
d) False
Solution: d

13 - The following code: print(chr(ord('z') - 2)) prints:
a) z
b) y
c) a
d) x
Solution: d

14 - The following code: x = '\' ' print(len(x)) prints:
a) 3
b) 2
c) 20
d) 1
Solution: d

15 - Which of the following are examples of Python built-in concrete exceptions?(Select two answers)
a) ArithemticError
b) IndexError
c) BaseException
d) ImportError
Solution: b

16 - The digraph written as #! is used to:
a) tell a Unix or Unix-like OS how to execute the contents of a Python file
b) tell an MS Windows OS how to execute the contents of a Python file
c) create a docstring
d) make a particular module entity a private one
Solution: a

17 - A function which returns a list of all entities available in a module is called:
a) entities()
b) content()
c) dir()
d) listmodule()
Solution: c

18 - What is true about updating already installed Python packages?
a) it can be done only by uninstalling and installing the package once again
b) it’s an automatic process which doesn’t require any user attention
c) it can be done by reinstalling the package using the reinstall command
d) it’s performed by the install command accompanied by the -U option
Solution: d