Skip to main content

Section 8.3 Assessment: APIs

Subgoals for using libraries:.

  1. Import module or function (if needed)
    1. With alias (optional)
  2. Determine whether parameters are appropriate for function
    1. Number of parameters passed must match function documentation
    2. Type of parameters passes must match function documentation
  3. 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)
  4. 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.

    3.

    Q3: Enter the output of the following program or enter β€œinvalid” if the statement would result in an error.
    import math
    print(int(math.sqrt(4)))
    

    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?
You have attempted of activities on this page.