Skip to main content
Contents
Dark Mode Prev Up Next Scratch ActiveCode Profile
\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 8.3 Assessment: APIs
Subgoals for using libraries:.
Import module or function (if needed)
Determine whether parameters are appropriate for function
Number of parameters passed must match function documentation
Type of parameters passes must match function documentation
Determine what the function will return (i.e., data type), print, and/or change state of arguments and where it will be stored (nowhere, somewhere)
Evaluate expression as necessary
Exercises Exercises
1.
Q1: Write a program that generates a random number 1 to 1000 and prints that value. Then it evaluates the square root of that number and prints that value.
import random
import math
---
number = random.randint(1, 1000)
print(number)
---
sqrt = math.sqrt(number)
print(sqrt)
2.
Q2: What is the output of the following code?
There is no output due to a runtime error.
3.
4.
Q4: Write the code necessary to import the
random
library and alias it as
r
.
5.
Q5: Which of the following is the name of the function in the math library that returns the absolute value of a number?
There is no function in the math library that returns the absolute value of a number.
You have attempted
of
activities on this page.