Introduction To Programming Using Python 1st Edition Schneider Test Bank Download

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Introduction to Programming Using

Python 1st Edition Schneider

Full download at link:

Test bank: https://testbankpack.com/p/test-bank-for-introduction-


to-programming-using-python-1st-edition-schneider-0134058224-
9780134058221/

Solution Manual: https://testbankpack.com/p/solution-manual-for-


introduction-to-programming-using-python-1st-edition-schneider-
0134058224-9780134058221/

Chapter 4

Multiple Choice (24) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH **.
YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.

1. What advantage is there to using functions in programming?


a. They break complex problems into smaller problems.
b. They let the programmer first focus on the tasks, then later how to accomplish each
task.
c. The eliminate repetitive code
d. All of the above. **

2. A function is said to _________ its output.


a. return **
b. hide
c. modify
d. none of the above

3. In a function call, the items inside parentheses are called _________.


a. arguments **

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


b. data
c. tasks
d. all of the above

4. A function header must end with a(n) _________.


a. : **
b. ;
c. .
d. //

5. Functions that do not return values _________.


a. do not have return statements. **
b. have return statements that return a 0.
c. have return statements that return an empty tuple.
d. are illegal in Python and cause a Throwback error.

6. A variable created inside a function is called a _________ variable.


a. local **
b. hidden
c. inner
d. inaccessible

7. Function parameters have _________ scope.


a. local **
b. global
c. no available
d. all of the above

8. If two variables with the same name are created in two different functions _________.
a. they have no relationship to each other. **
b. they create a conflict with each other.
c. they must be declared to be global.
d. they cause a Traceback error.

9. A variable that can be recognized everywhere in the program is called a _________ variable.
a. global **
b. local
c. all encompassing
d. priority

10. The _________ of a variable is the portion of the program that can refer to it.
a. scope **

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


b. dynamics
c. locality
d. reach

11. _________ are file that facilitate the reuse of functions.


a. library modules **
b. function bundles
c. module bundles
d. reuse files

12. To gain access to the functions and variables of a library module, use a(n) _________ statement.
a. import **
b. export
c. global
d. library

13. The parameters in a function definition are also called _________ parameters.
a. formal **
b. global
c. actual
d. local

14. The arguments in a function call are called _________ parameters.


a. actual **
b. local
c. formal
d. global

15. Python has an object called _________ that is used to denote a lack of value.
a. None **
b. Null
c. Nothing
d. Empty

16. Which standard library module contains trigonometric, exponential, and logarithmic functions?
a. math **
b. trig
c. engineering
d. geometry

17. When a function returns 2 or more values it is actually returning a(n) _________.
a. tuple **

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


b. list
c. string
d. all of the above

18. The following statement is an example of _________.


[int(num) for num in listOfNums]

a. list comprehension **
b. list compression
c. for loop compression
d. list initialization

19. In a function definition, the parameters without default values must _________ the parameters
with default values.
a. precede **
b. follow
c. outnumber
d. not outnumber

20. In a function definition, arguments passed by position must _________ arguments passed by
keyword.
a. precede **
b. follow
c. outnumber
d. not outnumber

21. _________ are one-line mini-functions that can often be used where a simple function is
required.
a. Lambda expressions **
b. De Morgan expressions
c. Boolean expressions
d. all of the above

22. The sorted function can be used with _________.


a. lists
b. strings
c. tuples
d. all of the above **

23. Repeatedly using a “divide-and-conquer” approach to break up a large problem into smaller
subproblems is called _________.
a. stepwise-refinement **

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


b. top-down design
c. program comprehension
d. comprehensive design

24. Why do programmers use top-down design and structured programming?


a. It increases productivity.
b. It leads to programs that are easier to read.
c. It tends to produce programs containing fewer initial errors.
d. All of the above. **

True/False (20)

1. Expressions cannot be used as arguments to a function.

Answer: false

2. When an argument to a function is an expression, the expression is not evaluated until it is


passed to the function body.

Answer: false

3. Function definitions must be processed by the Python interpreter before they can be called.

Answer: true

4. When a global statement appears inside a function block, it only affects statements following it
inside its function block.

Answer: true

5. The programmer cannot change the value of a named constant.

Answer: false

6. Python allows reassignments to any variable.

Answer: true

7. As a rule, functions should perform many tasks to be efficient.

Answer: false

8. As a rule, functions should be kept relatively small.

Answer: true

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


9. A function cannot call another function.

Answer: false

10. Functions can return any type of object.

Answer: true

11. When using list comprehension, you must always use the assigned variable ‘x’.

Answer: false

12. List comprehension can be applied to tuples.

Answer true

13. List comprehension cannot be applied to arithmetic progressions generated by range functions.

Answer: false

14. In a function definition, the parameters without default values must not precede the
parameters without default values.

Answer: false

15. In a function definition, arguments passed by position must precede arguments passed by
keyword.

Answer: true

16. Positional passing and keyword passing cannot be combined in the same function call.

Answer: false

17. The sort method can only be used with lists.

Answer: true

18. The sorted function can only be used with lists.

Answer: false

19. The sort method does not actually alter the order of the items in a list.

Answer: false

20. Order is not important for keyword arguments.

Answer: true

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Short Answer (7)

1. There are three ways to pass arguments to parameters in a function. List them.

Answer:
1) pass by position
2) pass by keyword
3) pass by default value

2. What is the output of the following program?

square = 2
def main():
square *= square
print(square)
main()

Answer: It produces a Traceback error because the statement “global square” is missing inside the
function.

3. What is the output of the following program?

square = 5
def main():
global square
square *= square
print(square)
main()

Answer: 25

4. What is the output of the following program?

def greeting(n):
for i in range(n):
print(“Hello World!”)

greeting(5)

Answer:

Hello World!
Hello World!
Hello World!

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


Hello World!
Hello World!

5. What is the output of the following program?

def feFiFo (x = ”smell”, y = “blood”, z = “an Englishman”):


print(“Fe, fi, fo, fum, I “ + x + “ the “ + y + “ of “ + z + “.”)

feFiFo()
feFiFo(“see”)
feFiFo(“hear”, “voice”)
feFiFo(“taste”, “juice”, “lemon”)

Answer:
Fe, fi, fo, fum, I smell the blood of an Englishman.
Fe, fi, fo, fum, I see the blood of an Englishman.
Fe, fi, fo, fum, I hear the voice of an Englishman.
Fe, fi, fo, fum, I taste the juice of a lemon.

6. When sorting a list, how do you sort in descending order?

Answer: Add the argument: reverse=True

7. List the four criteria that should be met when using top-down design.

Answer:
1) The design should be easily readable and emphasize small function size.
2) Tasks proceed from general to specific as you read down the chart.
3) They should perform only a single well-defined task.
4) Subtasks should be independent of each other as much as possible and any relationships among
subtasks should be specified.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

You might also like