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 to help answer these questions. 1. Write an expression that computes (i.e., evaluates to) the product of 8 and 3. 2. Write an expression that computes (i.e., evaluates to) the square root of 3. 3. Write here two expressions that cause error messages when they are evaluated. (Strive for examples that are different from those in the handout.) 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. 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' 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?

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~ 13. What does the expression 3 * (4 + 1) evaluate to? (Figure this out by hand, then check your answer in the PyDev Console 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 if you wish.) ANS. hibyehibyehibye ANS. 'hibyehibyehibye' 15. 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 if you wish.)
y = 5 
y = y * 3
y = y + 1
ANS. 16 16. 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) 17. True or False: The same variable name can occur on both sides of the assignment operator (=). a. true~ b. false 18. True or False: int is a valid name for a Python variable. a. true~ b. false 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? 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? ANS. 53 21. Consider the following code snippet:
  x = x * 10
x = x + 3
x = 5
What is the value of x after the code snippet runs? (Hint: This is a trick question). 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. 23. True or False: It is okay to use a variable before we give it an initial value. a. true b. false~ 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() 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 parenthesis ANS. f_to_c 31. How many parameters does the function have? ANS. one ANS. One ANS. 1 32. 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.~ 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 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 several (at least two) instance variables that you would expect a Circle class to have. 5. List 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 names 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 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