D. Watch the video: Your First Programs, Part 4: Functions, doing the next set of questions while you do so.
1. What keyword marks the beginning of a function definition?
ANS. def
2. What notation marks the body of the function (that is, how can we tell when one function ends and another starts)?
a. Curly braces ({})
b. Colon (:)
c. Indentation~
d. A new line or return
3. What is the name of the function that prints things (i.e., displays them on the console)?
ANS. print
ANS. print()
D. Consider the following program for the next several questions:
.
4. Check all the line numbers for lines that call a function.
a. Line 1
b. Line 2~
c. Line 3~
d. Line 6
e. Line 7~
f. Line 8~
g. Line 9~
h. Line 11~
i. Line 14
j. Line 15~
k. Line 17~
5. Check all the line numbers for lines that begin a function definition.
a. Line 1~
b. Line 2
c. Line 3
d. Line 6~
e. Line 7
f. Line 8
g. Line 9
h. Line 11
i. Line 14~
j. Line 15
k. Line 17
6. What does the program print when it runs?
M. This is printed first:->go, robot, go!
M. This is printed next:->go forward
M. This is printed next:->go forward
M. This is printed next:->stop, robot, stop!
M. This is printed next:->go forward
M. ->" "
D. Watch the video: Calling Functions, doing the next set of questions while you do so.
D. Consider the following function definition:
7. What is the name of the function? HINT: There should be no parenthesis
ANS. f_to_c
8. How many parameters does the function have?
ANS. one
ANS. One
ANS. 1
9. Why are functions powerful?
a. They take parameters and allow code re-use.
b. They do calculations and take parameters.
c. They can have comments and do calculation.
d. They improve organization and allow code re-use.~
10. Choose the statement that correctly calls the f_to_c function.
a.
f_to_c 5
b. f_to_c
c. def f_to_c(5)
d. f_to_c(5)
~
11. What steps occur when
c = f_to_c(10.5)
is called (where the f_to_c function is as defined above)? M. Step 1 -> Actual values are sent to function parameters M. Step 2 -> Execution continues in the f_to_c function code M. Step 3 -> The calculated value for celsius is returned M. Step 4 -> The returned value is substituted where the function call occurred M. -> None is returned M. -> The value for celsius is printed D. Watch the video: Coding to a Specification, doing the next set of questions while you do so. 12. The specification of a component has 3 most universal parts. What are those 3 parts? a. What goes into the component, what comes out of the component, and the side effects of the component.~ b. What goes into the component, what comes out of the component, and the purpose of the component. c. The purpose of the component, the amount of time it will take to run, and the number of parameters it needs. d. The name of the component, the parameters of the component, and what comes out of the component. 13. A specification states how the component works. a. true b. false~ 14. A specification states what the component does. a. true~ b. false D. Watch the video: Object Oriented Programming, doing the next set of questions while you do so. 15. Four computer languages developed in the 1950s dominated early computing. One of them is Lisp. What is the name of another? a. Procedural b. C c. ALGOL~ d. Assembly 16. This diagramprint('hello')
a. 'hello' appears on the screen b. hello appears on the screen~ c. "hello" appears on the screen d. an error occurs 34. Suppose that you run the following one-line program. What happens?print(hello)
a. 'hello' appears on the screen b. hello appears on the screen c. "hello" appears on the screen d. an error occurs~ 35. What does the expression 3 * (4 + 1) evaluate to? (Figure this out by hand, then check your answer in the PyDev Console.) ANS. 15 36. What does the expression 3 * ('hi' + 'bye') evaluate to? (Figure this out by hand, then check your answer in the PyDev Console.) ANS. hibyehibyehibye ANS. 'hibyehibyehibye' 37. What is the value of y after the following set of statements executes? (Figure this out by hand, then check your answer in the PyDev Console.)y = 5
y = y * 3
y = y + 1
ANS. 16 38. Assume that you have a variable x that has already been given a numeric value. Assume that you have put import math at the top of your program. Write a statement that sets the variable y to the sum of the sine of x and the cosine of x. ANS. y**=**math.sin(x)**+**math.cos(x) ANS. y**=**math.cos(x)**+**math.sin(x) 39. The same variable name can occur on both sides of the assignment operator (=) a. true~ b. false 40. int is a valid Python variable name. a. true~ b. false 41. Bobby decided to use int as a variable name and created the following code:int = 2.5
print(int(int))
What happens when Bobby runs his code? a. An error occurs because int is no longer the name of a function but the name of a float.~ b. 2 is printed. c. 3 is printed. d. An error occurs because int cannot be used as a variable name. 42. It is okay to use a variable before we give it an initial value. a. true b. false~