D. Answer the following questions as you follow the instructions in the handout: XXX. 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? HINT: If you are not sure, you can check the type of a variable (e.g., x=54) by saying type(x). Note that if you use type(x) before entering x=54 in the console you will get an error because x does not yet have a value. 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 screen b. hello appears on the screen~ c. "hello" appears on the screen 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.) 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.) 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.)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. The same variable name can occur on both sides of the assignment operator (=) a. true~ b. false 18. int is a valid Python variable name. a. true~ b. false 19. Consider the following code snippet:x = 5What is the value of
x = x + 3
x = x * 10
x
after the code snippet runs?
ANS. 80
20. Consider the following code snippet: x = 5What is the value of
x = x * 10
x = x + 3
x
after the code snippet runs?
ANS. 53
21. Consider the following code snippet: x = x * 10What is the value of
x = x + 3
x = 5
x
after the code snippet runs? (Hint: This is a trick question. What will happen when the code snippet runs?)
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. 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: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: 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