D. After you do the exercises in the handout Getting started in Python ..., answer the following questions. Except where noted, you are welcome to use the Pydev Console or Idle to help answer these questions. D. If you struggle with any of the next set of questions, refer back to the exercises in the Numbers and arithmetic. Operators and expressions. Parentheses and precedence section of the Getting started in Python ... handout. Redo those exercises as needed. 1. Write an expression that computes (i.e., evaluates to) the product of 8 and 3. ANS. 8 \* 3 ANS. 8\*3 ANS. 3\*8 ANS. 3 \* 8 2. Write an expression that computes (i.e., evaluates to) the cube root of 3, that is, 3 raised to the 1/3 power. ANS. 3 \*\* (1/3) ANS. 3\*\*(1/3) ANS. 3 \*\*(1/3) ANS. 3\*\* (1/3) ANS. 3 \*\* (1 / 3) 3. To what does the expression 9 - (7 + 3) evaluate? ANS. -1 3. To what does the expression 9 - 7 + 3 evaluate? (Use the Python Console or Idle to find the answer to this question. And use parentheses in the expressions that you write so that you do not have to remember how non-parenthesized expressions work.) ANS. 5 D. If you struggle with any of the next set of questions, refer back to the exercises in the Exceptions, run-time errors section of the Getting started in Python ... handout. Redo those exercises as needed. 3. Write here two expressions that cause error messages when they are evaluated. (Strive for examples that are different from those in the handout.) D. If you struggle with any of the next set of questions, refer back to the exercises in the Objects and Types. Int, float, string section of the Getting started in Python ... handout. Redo those exercises as needed. 4. Consider the statement x = 54. What is the type of the object to which the variable x refers? REMINDER: The type function returns the type of its argument, so you can use it in the Python Console or Idle to find the answer to this quiz question. ANS. int ANS. integer ANS. Integer 5. Consider the statement x = 54. What is the value of the object to which the variable x refers? ANS. 54 6. Consider the statement y = 3.713. What is the type of the object to which the variable y refers? ANS. float ANS. Float 7. Consider the statement y = 3.713. What is the value of the object to which the variable y refers? ANS. 3.713 8. Consider the statement z = 'my best friend'. What is the type of the object to which the variable z refers? ANS. str ANS. string ANS. String 9. Consider the statement z = 'my best friend'. What is the value of the object to which the variable z refers? ANS. my best friend ANS. "my best friend" ANS. 'my best friend' 13. What does the expression 3 * (4 + 1) evaluate to? (Figure this out by hand, then check your answer in the PyDev Console or Idle if you wish.) ANS. 15 14. What does the expression 3 * ('hi' + 'bye') evaluate to? (Figure this out by hand, then check your answer in the PyDev Console or Idle if you wish.) ANS. hibyehibyehibye ANS. 'hibyehibyehibye' D. If you struggle with any of the next set of questions, refer back to the exercises in the Variables and Assignment section of the Getting started in Python ... handout. Redo those exercises as needed. 10. Write a statement that assigns the variable my_friend the value 'Betty Bop'. ANS. my_friend = 'Betty Bop' ANS. my_friend= 'Betty Bop' ANS. my_friend ='Betty Bop' ANS. my_friend='Betty Bop' 11. Suppose that you run the following one-line program. What happens? (Try this out in the Python Console or Idle to learn the correct answer.)
print('hello')
a. 'hello' appears on the Console b. hello appears on the Console~ c. "hello" appears on the Console d. an error occurs 12. 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~ 23. True or False: It is okay to use a variable before we give it an initial value. a. True b. False~ 22. 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. D. If you struggle with any of the next set of questions, refer back to the exercises in the Dynamically typed versus statically typed section of the Getting started in Python ... handout. Redo those exercises as needed. 17. True or False: The same variable name can occur on both sides of the assignment operator (=). a. True~ b. False 15. Consider the following code snippet:
y = 5 
y = y + 100
What is the value of y after the code snippet runs? (Figure this out by hand, then check your answer in the PyDev Console or Idle if you wish.) ANS. 105 15. Consider the following code snippet:
y = 5 
y = y * 3
y = y + 1
What is the value of y after the code snippet runs? (Figure this out by hand, then check your answer in the PyDev Console or Idle if you wish.) ANS. 16 19. Consider the following code snippet:
  x = 5
x = x + 3
x = x * 10
What is the value of x after the code snippet runs? (Figure this out by hand, then check your answer in the PyDev Console or Idle if you wish.) ANS. 80 20. Consider the following code snippet:
  x = 5
x = x * 10
x = x + 3
What is the value of x after the code snippet runs? (Figure this out by hand, then check your answer in the PyDev Console or Idle if you wish.) ANS. 53 D. If you struggle with any of the next set of questions, refer back to the exercises in the The assignment operator is not symmetrict section of the Getting started in Python ... handout. Redo those exercises as needed. 17. True or False: The expressions a = b and b = a accomplish the same thing. a. True b. False~ D. If you struggle with any of the next set of questions, refer back to the exercises in the Calling functions section of the Getting started in Python ... handout. Redo those exercises as needed. 16. Assume that you have a variable x that has already been given a numeric value. Assume that the statement import math has already executed. 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.sin(x)+math.cos(x) ANS. y=math.sin(x)+math.cos(x) ANS. y = math.cos(x) + math.sin(x) 16. Write an expression that evaluates to 20!, that is, to 20 factorial. Assume that the statement import math has already executed. ANS. math.factorial(20) D. Watch the video: Your First Programs, Part 4: Functions, doing the next set of questions while you do so. 24. What keyword marks the beginning of a function definition? ANS. def 25. 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 26. What is the name of the function that prints things (i.e., displays them on the console)? ANS. print ANS. print() 27. Consider the following code snippet:
def foo():
print('nice!')
x = 5
x = x * 10
print(x)

def blah():
print('ok')
How many functions does the snippet define? a. None b. 1 c. 2~ d. 3 e. 4 f. More than 4 27. In the above code snippet, what is the name of the SECOND function defined? ANS. blah ANS. blah() 27. In the above code snippet, how many statements (lines) are in the body of the foo function? a. None b. 1 c. 2 d. 3 e. 4~ f. More than 4 27. Consider the following code snippet:
def main():
blah()
blah()
blah()

def blah():
print('one')
print('two')

main()
How many lines does the above code snippet print on the Console when it runs? a. None a. 1 b. 2 b. 3 c. 4 d. 5 d. 6~ e. More than 6 27. What does the above code snippet cause to appear on the Console? a. one
two
a. one
one
one
two
two
two
b. one
two
one
two
one
two
~ c. None of the above. 27. Consider the following code snippet:
def main():
blah()
blah
blah

def blah():
print('one')
print('two')

blah()
Note that it is the same as the previous example except for the last line of the snippet. How many lines does the above code snippet print on the Console when it runs? a. None a. 1 b. 2~ b. 3 c. 4 d. 5 d. 6 e. More than 6 27. What does the above code snippet cause to appear on the Console? a. one
two
~ a. one
one
one
two
two
two
b. one
two
one
two
one
two
c. None of the above. D. Consider the following program for the next several questions:
. 27. 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~ 28. 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 29. 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: 30. What is the name of the function? HINT: There should be no parentheses in your answer. ANS. f_to_c 31. How many parameters does the function have? ANS. one ANS. One ANS. 1 32. Why are functions powerful? (Choose all that apply.) b. They do calculations. c. They can have comments. d. They improve organization and make it easier to maintain the program.~ e. They allow code re-use.~ 33. 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)~ 34. 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. 46. 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. 47. True or False: A specification states how the component works. a. True b. False~ 48. True or False: 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. 35. 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 36. This diagram is part of a: a. Poem called Beowulf b. Rocket ship c. Garbage can d. Flowchart~ 37. Procedural decomposition is: a. The process by which leftovers become fertilizer for gardens. b. What happens to mummies when they are left out in the open air. c. How great ideas become hollow ones. d. The process of breaking a problem into a sequence of subproblems, with each subproblem given a procedure to solve it, and then breaking those subproblems into sub-subproblems, with each sub-subproblem given a procedure to solve it, and so forth until the problem is reduced to procedures of manageable size.~ 38. The first object-oriented (OO) language was (in some historians' view) SIMULA, but the most influential of the early OO languages was: a. Smalltalk~ b. Bigmouth c. Farsight d. Giggles 39. Most of the widely-used languages developed since 1990 have been object oriented languages. a. True~ b. False 40. The procedural programming paradigm focuses on: a. Nouns b. Verbs~ c. Adjectives 41. The object-oriented programming paradigm focuses on: a. Nouns~ b. Verbs c. Adjectives 42. Today's software engineer typically uses both the procedural and object-oriented paradigms--there is a place for each. a. True~ b. False 43. True or False: Python supports both a procedural and an object-oriented notation. a. True~ b. False D. Watch the video: Classes -- What objects know and can do, doing the next set of questions while you do so. 1. In Python, every item of data is called an: ANS. object ANS. Object 2. True or False: in Python, programmers can define their own classes. a. True~ b. False 3. What 3 things does every class have? 4. List the names of several (at least two) instance variables that you would expect a Circle class to have. 5. List the names of several (at least two) methods that you would expect a Person class to have. 6. True or False: If p1 and p2 are both instances of a Point class, the names of the instance variables for p1 are the same as the names of the instance variables for p2. a. True~ b. False 7. True or False: If p1 and p2 are both instances of a Point class, the values of the instance variables for p1 are the same as the values of the instance variables for p2. a. True b. False~ 8. The instance variables of a class: a. describe the operations that instances of the class can do b. are variables that are instances of the class c. describe the data that instances of the class hold~ 9. The methods of a class: a. describe the operations that instances of the class can do~ b. describe the sub-classes of the class c. describe the data that instances of the class hold D. Watch the video: Objects and Classes--Using Objects, doing the next set of questions while you do so. 1. What class does the number 17 belong to? ANS. int ANS. integer ANS. Integer 2. True of False: For any given class, the maximum number of instances of that class is 10. a. True b. False~ 3. Each instance of a class has data stored with it in what's called the classes': ANS. instance variables ANS. instance variable 4. Fill in the blank: All instances of a class have the same set of _______ that define what the instances can do. ANS. methods ANS. method 5. Only one of the following choices might be a valid notation for constructing an instance of a Dog class as defined in the rosegraphics (abbreviated rg) module. Which one? a. rg.Dog.dog b. rg.Point.dog c. rg.Dog d. rg.Dog('poodle')~ e. rg.dog('poodle') f. rg.Poodle() g. rg.poodle() 6. True or False: After you have typed a few letters of the beginning of the name of a class in Eclipse, it usually pops up the full name, and you can then just press the Enter key to have Eclipse auto-fill that name for you. a. True~ b. False 7. To determine what arguments an instance of the Dog class needs for its constructor, you can: (check all that are correct) a. Hover over the name Dog after you have typed it, and look at the pop-up help.~ b. Google it. c. Put the cursor inside the parentheses after typing Dog() and press the CTRL and Space keys.~ 8. Which of the following constructs a Point object (as defined in the rosegraphics module) and gives the name p1 to it. a. p1 = rg.Point(4, 100)~ b. p1 = rg(4, 100) c. p1 = (4, 100) 9. Consider the following code. What does it print?
  p2 = rg.Point(7, 3)
p1 = rg.Point(100, 50)
print((4 * p1.x) + p2.y
ANS. 403 44. What trick can we use in Eclipse to figure out what instance variables and methods an object has? a. A hat trick. b. The DOT trick, which is: Type the object's name, followed by a DOT (i.e., PERIOD), pause, and look at the pop-up help that appears.~ c. Google it. 44. In the pop-up help that appears from the DOT trick, what letter indicates that the item being shown is a method (as opposed to, for example, an instance variable). a. M~ b. C c. No letter at all D. Watch the video: Thinking Like a Computer -- Control Flow, doing the next set of questions while you do so. 15. What gets printed when main is called in the program shown below? (Pay close attention to the order in which the statements are executed.)
def main():
hello()
goodbye()
hello()

def hello():
print('Hello!')
return 'Hello!'

def goodbye():
print('Ciao!')
M. Line 1 ->
Hello!
M. Line 2 ->
Ciao!
M. Line 3 ->
Hello!
15. What gets printed when main is called in the program shown below? (Hint: this code is very similar to the code in the previous problem, and this problem is a bit of a "trick" question.)
def main():
hello()
goodbye()
hello()

def hello():
print('Hello!')
return 'Hello!'
print('Hello Again!')

def goodbye():
print('Ciao!')
M. Line 1 ->
Hello!
M. Line 2 ->
Ciao!
M. Line 3 ->
Hello!
M. ->
Hello Again!
17. What gets printed when main is called in the program shown below? (You will probably want to use post-it cards (as in the video) or some written notes to help you solve this problem.)

def main():
big()
bigger()
big()

def big():
print('basketball')

def bigger():
print('truck')
big()
M. Line 1 -> basketball M. Line 2 -> truck M. Line 3 -> basketball M. Line 4 -> basketball 17. What gets printed when main is called in the program shown below? (You will probably want to use post-it cards (as in the video) or some written notes to help you solve this problem.)

def main():
big()
bigger()
biggest()
big()

def big():
print('basketball')

def bigger():
print('truck')
big()

def biggest():
print('house')
bigger()
big()
M. Line 1 -> basketball M. Line 2 -> truck M. Line 3 -> basketball M. Line 4 -> house M. Line 5 -> truck M. Line 6 -> basketball M. Line 7 -> basketball M. Line 8 -> basketball