Every problem in the chapter beside the book’s answer, a chapter at a time as you scroll.
Chapter 7: Modules
33 problems · 0 figuresConcepts in Practice 7.1.1 §7.1 source ↗
area module?- a.6
- b.10
- c.49
Answer
def statements, each of which defines a function.Concepts in Practice 7.1.2 §7.1 source ↗
- a.Functions would be defined and ready to be called.
- b.Nothing; the module has no statements to be run.
- c.
SyntaxError
Answer
Concepts in Practice 7.1.3 §7.1 source ↗
cube(5)?- a.
60 - b.
125 - c.
150
Answer
150area.cube(5) is 6 * 5**2, which is 6 * 25, which is 150 .Concepts in Practice 7.1.4 §7.1 source ↗
- a.
import secret - b.
import secret.py - c.
import "secret.py"
Answer
import secretConcepts in Practice 7.1.5 §7.1 source ↗
- a.
circle(3) - b.
area.circle(3) - c.
circle.area(3)
Answer
area.circle(3)Concepts in Practice 7.1.6 §7.1 source ↗
- a.the main program
- b.the area module
- c.the secret module
Answer
Concepts in Practice 7.2.1 §7.2 source ↗
print(sqrt(25))?- a.
from math import sqrt - b.
import sqrt from math - c.
import math
Answer
from math import sqrtConcepts in Practice 7.2.2 §7.2 source ↗
from math import sin, cos, tan?- a.0
- b.3
- c.4
Answer
Concepts in Practice 7.2.3 §7.2 source ↗
- a.
ImportError - b.
NameError - c.
SyntaxError
Answer
NameErrorConcepts in Practice 7.2.4 §7.2 source ↗
from area import square, circle. What code causes a name collision?- a.
def area(phone): """Gets the area code of a phone number."""
- b.
def circle(x, y, size): """Draws a circle centered at (x, y)."""
- c.
def is_square(length, width): """Returns True if length and width are equal."""
Answer
def circle(x, y, size): """Draws a circle centered at (x, y)."""
circle() and area.circle() have different parameters.Concepts in Practice 7.2.5 §7.2 source ↗
import area. What code causes a name collision?- a.
area = 51
- b.
import cylinder from volume
- c.
def cube(size): """Generates a "size X size" rubik's cube."""
Answer
area = 51
51 . The variable can no longer be used to call functions in the area module.Concepts in Practice 7.2.6 §7.2 source ↗
1 def hello():
2 print("Hello!")
3
4 def hello(name):
5 print("Hello,", name)
6
7 hello()
8 hello("Chris")- a.line 4
- b.line 7
- c.line 8
Answer
hello() requires one argument, so this line would result in an error.Concepts in Practice 7.3.1 §7.3 source ↗
1 import math
2
3 print("Defining sphere function")
4
5 def sphere(radius):
6 """Gets the volume of a sphere."""
7 return 4/3 * math.pi * radius**3- a.line 1
- b.line 3
- c.line 5
Answer
"Defining sphere function" as a side effect.Concepts in Practice 7.3.2 §7.3 source ↗
import math def sphere(radius): """Gets the volume of a sphere.""" return 4/3 * math.pi * radius**3 for r in range(10000000): volume = sphere(r)
- a.true
- b.false
Answer
Concepts in Practice 7.3.3 §7.3 source ↗
name = input("What is your name? ")
print(f"Nice to meet you, {name}!")
live = input("Where do you live? ")
print(f"{live} is a great place.")- a.true
- b.false
Answer
Concepts in Practice 7.3.4 §7.3 source ↗
import math print(math.__name__) print(__name__)
- a.
>math test
- b.
__main__ test
- c.
math __main__
Answer
math __main__
__name__ is the module's name, unless the module was run as the main program. In that case, __name__ is "__main__" .Concepts in Practice 7.3.5 §7.3 source ↗
import math print(math.__name__) print(__name__)
- a.
math test
- b.
__main__ test
- c.
math __main__
Answer
math test
__name__ is "test" .Concepts in Practice 7.3.6 §7.3 source ↗
- a.
if __name__ == "main": - b.
if __name__ == __main__: - c.
if __name__ == "__main__":
Answer
if __name__ == "__main__":Concepts in Practice 7.4.1 §7.4 source ↗
#000080?- a.maroon red
- b.navy blue
- c.olive green
Answer
#0000FF .Concepts in Practice 7.4.2 §7.4 source ↗
- a.00
- b.80
- c.FF
Answer
Concepts in Practice 7.4.3 §7.4 source ↗
- a.
#FFA500 (orange) - b.
#008000 (green)
Answer
#FFA500 (orange)Concepts in Practice 7.4.4 §7.4 source ↗
- a.red=0, green=255, blue=255
- b.red=255, green=255, blue=0
- c.red=255, green=0, blue=255
Answer
#FFFF00 , meaning 255 red + 255 green + 0 blue.Concepts in Practice 7.4.5 §7.4 source ↗
- a.
darken(BLUE) - b.
colors.darken(BLUE) - c.
colors.darken(colors.BLUE)
Answer
colors.darken(colors.BLUE)darken function and the BLUE variable must be accessed via the colors variable.Concepts in Practice 7.4.6 §7.4 source ↗
- a.underscore (
_) - b.number sign (
#) - c.colon (
:)
Answer
_)Concepts in Practice 7.4.7 §7.4 source ↗
- a.true
- b.false
Answer
Concepts in Practice 7.4.8 §7.4 source ↗
- a.alphabetical order
- b.definition order
- c.random order
Answer
Concepts in Practice 7.4.9 §7.4 source ↗
- a.
_tohex - b.
tohex - c.
torgb
Answer
_tohexConcepts in Practice 7.5.1 §7.5 source ↗
Use the library reference, module index, and documentation links above to answer the questions.
Which page provides a list of built-in modules sorted by category?- a.library reference
- b.module index
- c.PEP 2
Answer
Concepts in Practice 7.5.2 §7.5 source ↗
Use the library reference, module index, and documentation links above to answer the questions.
What is the value ofcalendar.SUNDAY?- a.
1 - b.
6 - c.
7
Answer
6calendar module, MONDAY is 0 and SUNDAY is 6 .Concepts in Practice 7.5.3 §7.5 source ↗
Use the library reference, module index, and documentation links above to answer the questions.
Which built-in module enables the development of graphical user interfaces?- a.
tkinter - b.
turtle - c.
webbrowser
Answer
tkintertkinter module stands for Tk interface. Tk is a standard toolkit for creating windows, text boxes, buttons, and other graphical widgets.Concepts in Practice 7.5.4 §7.5 source ↗
Use pypi.org and the links in the table above to answer the questions.
Which modules can be used to edit pictures and videos?- a.
BeautifulSoupandScrapy - b.
BokehandMatplotlib - c.
MoviePyandPillow
Answer
MoviePy and PillowMoviePy is a module for video editing, and Pillow is a module for image processing.Concepts in Practice 7.5.5 §7.5 source ↗
Use pypi.org and the links in the table above to answer the questions.
Which third-party module is a replacement for the built-indatetime module?- a.
arrow - b.
calendar - c.
time
Answer
arrowArrow's is a "fully-implemented, drop-in replacement for datetime."Concepts in Practice 7.5.6 §7.5 source ↗
Use pypi.org and the links in the table above to answer the questions.
Search for the webcolors module on PyPI. What function provided by webcolors looks up the color name for a hex code?- a.
hex_to_name - b.
name_to_hex - c.
normalize_hex
Answer
hex_to_namehex_to_name("#daa520") returns "goldenrod" .Loading chapter 8…
Problems and answers are adapted from Introduction to Python Programming by Udayan Das, Aubrey Lawson, Chris Mayfield and Narges Norouzi, OpenStax, and are used under the CC BY-NC-SA 4.0 licence. Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction. Illustrations: Copyright Rice University, OpenStax, under CC BY-NC-SA 4.0 license. This adaptation is released under the same licence, is non-commercial, and is neither affiliated with nor endorsed by OpenStax or Rice University.