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

Chapter 04 – An Introduction to Programming using Python Schneider


 

Download  file with the answers

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


 

Chapter 4

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 
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 
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 
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 
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
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

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!
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.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!