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
ExercisesExercises
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?
print(int(math.sqrt(4)))
2
2.0
4
There is no output due to a runtime error.
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?
abs
absolute
fabs
There is no function in the math library that returns the absolute value of a number.