Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 (1 point) Consider the code snippet named shapes.py . A statement to

ID: 3898991 • Letter: Q

Question

Question 1 (1 point)

Consider the code snippet named shapes.py. A statement to import shapes.py would be ________.

cr = '#'

def draw_square(size):

for h in range(size):

for w in range(size):

print(cr, end='')

print()

def draw_rect(height, width):

for h in range(height):

for w in range(width):

print(cr, end='')

print()

a

import geometry

b

import larch

c

import shapes.py

d

import shapes

multiple_choice626228605Question 2 (1 point)

Which of the following is not in sys.path?

a

The directory of the executing script.

b

A list of directories specified by the environmental variable PYTHONPATH.

c

The directory where Python is installed (typically C:Python27 or similar on Windows).

d

The directory where a larch is.

multiple_choice626228595Question 3 (1 point)

Consider the code snippet named shapes.py. A statement that changes the output to use '$' when drawing shapes. (Change the value of shapes.cr) would be __________.

cr = '#'

import shapes

def draw_square(size):

for h in range(size):

for w in range(size):

print(cr, end='')

print()

def draw_rect(height, width):

for h in range(height):

for w in range(width):

print(cr, end='')

print()

a

shapes.cr = $

b

cr = ‘$’

c

shapes.cr = ‘&’

d

shapes.cr = ‘$’

multiple_choice626228579Question 4 (1 point)

A _________ is a file containing Python code that can be imported by a script.

a

larch

b

package

c

module

d

script

multiple_choice626228639Question 5 (1 point)

Consider the following code example:
## module M1.py
a = 'First Message'
def printer(): print('Hello from M1:', a)
>>> import M1
>>> M1pr = M1.printer
>>> M1pr()
Hello from M1: First Message
>>> # Change printer and message ...
>>> reload(M1)

The console output that follows the reload statement will be _______________

a

No output

b

‘First Message’

c

d

The program will throw an error.

multiple_choice626228575Question 6 (1 point)

A file containing Python code that is passed as input to the interpreter is called a _______?

a

larch

b

package

c

module

d

script

multiple_choice626228629Question 7 (1 point)

Consider the following directory structure and the from clause below the directory structure. A statement that calls the draw() function of the imported house module would be ______________.

ASCIIArtTop-level package

__init__.py

canvas.py

figuresSubpackage for figures art

__init__.py

man.py

cow.py

...

buildingsSubpackage for buildings art

__init__.py

barn.py

house.py

...

a

draw()

b

aim()

c

shoot()

d

load()

multiple_choice626228569Question 8 (1 point)

To __­­­______ a module means to execute the code contained by the module.

a

export

b

import

c

find

d

reload

multiple_choice626228613Question 9 (1 point)

The following code uses functions defined in my_funcs.py. Complete the import statement at the top of the program.

____________________
a = 3
print(‘a! = ‘, factorial(a))
print(‘log(a) = ‘,log(a))

a

import factorial, squared

b

import factorial, log

c

from my_funcs import factorial, log

d

from my_func import factorial log

multiple_choice626228619Question 10 (1 point)

Consider the following directory structure. A statement to import the figures subpackage would be _____________.

ASCIIArtTop-level package

__init__.py

canvas.py

figuresSubpackage for figures art

__init__.py

man.py

cow.py

...

buildingsSubpackage for buildings art

__init__.py

barn.py

house.py

...

a

import figures

b

import ASCIIArt.figures

c

import ASCIIArt

d

import ASCII.figures

a

import geometry

b

import larch

c

import shapes.py

d

import shapes

Explanation / Answer

1. d. import shapes

2. d. The directory where a larch is.

3. a. shapes.cr = $

4. c. module

5. d. The program will throw an error.

6. d. script

7. a. draw()

8. d. reload

9. c. from my_funcs import factorial, log

10. b.

import ASCIIArt.figures

**Comment for any further queries.