Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Gaddis Python 2e Chapter 06


 

Download  file with the answers

If you are not a member register here to download this file 


 

Chapter Six

MULTIPLE CHOICE

1. The Python library functions that are built into the Python _____ can be used by simply calling the function.
a. code
b. compiler
c. linker
d. interpreter

2. Python comes with _____ functions that have been already prewritten for the programmer.
a. standard
b. library
c. custom
d. built-in

3. Which of the following statements causes the interpreter to load the contents of the random module into memory?
a. load random
b. import random
c. upload random
d. download random

4. Which of the following will assign a random number in the range of 1 through 50 to the variable number?
a. random(1,50) = number
b. number = random.randint(1, 50)
c. randint(1, 50) = number
d. number = random(range(1, 50))

5. What is the result of the following statement?
x = random.randint(5, 15) * 2
a. A random integer from 5 to 15, multiplied by 2, assigned to the variable x
b. A random integer from 5 to 15 assigned to the variable x
c. A random integer from 5 to 15, selected in 2 steps, assigned to the variable x
d. A random integer from 5 to 15, raised to the power of 2, assigned to the variable x

6. What type of value is returned by the functions random and uniform?
a. integer
b. number
c. float
d. double

7. In a value-returning function, the value of the expression that follows the key word _____ will be sent back to the part of the program that called the function.
a. def
b. return
c. sent
d. result

8. What type of function can be used to determine whether a number is even or odd?
a. even
b. odd
c. math
d. Boolean

9. The Python standard library’s _____ module contains numerous functions that can be used in mathematical calculations.
a. math
b. string
c. random
d. number

10. Which of the following functions returns the largest integer that is less than or equal to x?
a. floor
b. ceil
c. lesser
d. greater

11. What makes it easier to reuse the same code in more than one program?
a. Mods
b. Procedures
c. Modules
d. Functions

12. In a menu-driven program, what statement is used to determine and carry out the user’s desired action?
a. if-else
b. if-elif-else
c. while
d. for

13. A value-returning function is _____.
a. a single statement that perform a specific task
b. called when you want the function to stop
c. a function that will return a value back to the part of the program that called it
d. a function that receives a value when it is called

14. What does the following statement mean?
num1, num2 = get_num()
a. The function get_num() is expected to return a value each for num1 and num2.
b. The function get_num() is expected to return a value and assign it to num1 and num2.
c. Statement will cause a syntax error.
d. Statement will cause a run-time error.

15. Given the following function definition, what would the statement print magic(5) display?
def magic(num):
return num + 2 * 10
a. 70
b. 25
c. Statement will cause a syntax error.
d. Statement will cause a run-time error.

TRUE/FALSE

1. True/False: A value-returning function is like a simple function except that when it finishes it returns a value back to the called part of the program.

ANS: T

2. True/False: Boolean functions are useful for simplifying complex conditions that are tested in decision and repetition structures.

ANS: T

3. True/False: Unlike other languages, in Python, the number of values a function can return is limited to one.

ANS: F

4. True/False: In Python, one can have a list of variables on the left side of the assignment operator.

ANS: T

5. True/False: In Python, there is no restriction on the name of a module file.

ANS: F

6. True/False: The randrange function returns a randomly selected value from a specific sequence of numbers.

ANS: T

7. True/False: One of the drawbacks of a modularized program is that the only structure we could use is sequence structure.

ANS: F

8. True/False: In a menu-driven program, a loop structure is used to determine the menu item the user selected.

ANS: F

9. True/False: The math function, atan(x), returns one tangent of x in radians.

ANS: F

10. True/False: The math function, ceil(x), returns the smallest integer that is greater than or equal to x.

ANS: T

FILL IN THE BLANK

1. Functions in the standard library are stored in files that are known as _______________.

ANS: modules

2. The term _______________ is used to describe any mechanism that accepts input, performs some operation that cannot be seen, and produces output.

ANS: black box
3. To refer to a function in a module, in our program we have to use the _______________ notation.

ANS: dot

4. A value-returning function has a(n) _______________ statement that returns a value back to the part of the program that called it.

ANS: return

5. The _______________ chart is an effective tool that programmers use for designing and documenting functions.

ANS: IPO

6. The ‘P’ in the acronym IPO refers to _______________.

ANS: processing

7. In Python, a module’s file name should end in _______________.

ANS: .py

8. A(n) _______________ program displays a list of the operations on the screen and allows the user to select the operation that the program should perform.

ANS: menu-driven

9. The approach of _______________ makes the program easier to understand, test, and maintain.

ANS: modularization

10. The return values of the trigonometric functions in Python are in _______________.

ANS: radians

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!