1. 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 2. Consider the statement x = 54. What is the value of the object to which the variable x refers? ANS. 54 3. Consider the statement y = 3.713. What is the type of the object to which the variable y refers? ANS. float ANS. Float 4. Consider the statement y = 3.713. What is the value of the object to which the variable y refers? ANS. 3.713 5. 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 6. 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' 7. 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' 8. 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 9. 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~ 10. What does the expression 3 * (4 + 1) evaluate to? ANS. 15 11. What does the expression 3 * ('hi' + 'bye') evaluate to? ANS. hibyehibyehibye ANS. 'hibyehibyehibye' 12. What is the value of y after the following set of statements executes?y = 5
y = y * 3
y = y + 1
ANS. 16 13. 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) D. For the following questions perform experiments using a PyDev console in Eclipse (e.g., try using the same variable name on both sides of the assignment operator). 14. The same variable name can occur on both sides of the assignment operator (=) a. true~ b. false 15. int is a valid Python variable name. a. true~ b. false 16. 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. 17. It is okay to use a variable before we give it an initial value. a. true b. false~ 18. What keyword marks the beginning of a function definition? ANS. def 19. What notation marks the body of the function (that is, how can we tell when one function ends and another starts)? a. Indentation~ b. Curly braces ({}) c. Colon (:) d. A new line or return 20. What is the name of the function that prints things (i.e., displays them on the console)? ANS. print ANS. print() D. Watch the video: Calling Functions D. Consider the following function definition: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. 26. 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. 27. A specification states how the component works. a. true b. false~ 28. A specification states what the component does. a. true~ b. false D. Do this reading: Counted Loops 29. Choose the correct lines to make a loop that prints 'funny' 40,000 times. M. Line 1->for k in range(40000): M. Line 2-> print('funny') M. ->for k in range(40001) M. ->for k in range(n) M. -> return 'funny' M. -> print 'funny' 30. Choose the correct lines to make a loop that prints the cubes of the numbers from 0 to m, inclusive (where m is some integer bigger than 35). For example, if m were 37, then this loop should print:42875
46656
50653
These are 35 cubed, 36 cubed, and 37 cubed. M. Line 1->for i in range(m+1) M. ->for i in range(m) M. ->for i in range(0) M. Line 2-> print(i**3) M. -> print(35**3) M. -> print(m**3) D. Watch the video: Object Oriented Programming 31. 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 32. This diagram