Reference no: EM132357199
Multiple Choice Practice Questions
Select the best answer.
1. In a Python program, values are stored in:
a. statements
b. expressions
c. variables
d. operators
2. A value that is passed to a function is called:
a. identifier
b. argument
c. statement
d. parameter
3. Pseudocode is:
a. Python code, modified to be suitable for documentation
b. a few general statements about what a program will do
c. a detailed account of an algorithm in English rather than code
d. all comments from a program extracted into documentation
4. A function can send a value back to the method that called it using a(n):
a. operator
b. return statement
c. print statement
d. loop
5. What is the output of the following code?
def main():
x=10
x=calTest(x)
print (x)
def calTest(y):
y = int (y)
y= y*2+2*3/2
return y
main()
a. 5
b. 23
c. 10
d. 26
6. Which of the following would be a legal variable name?
a. class
b. 8th
c. MY_GUI
d. Second-name
7. To use the functions in an external module, a program should use:
a. comment
b. open statement
c. operator
d. import statement
8. In object-oriented programming, a class contains:
a. pseudocode
b. variables and methods
c. methods
d. variables
9. Which programming structure is the most appropriate to describe the statement "When it's cold close the window and the curtains otherwise leave the window and curtains open":
a. if...elif...else
b. while
c. if...else
d. for
10. If you need to re-use a section of code and use it in a number of different places, which is the most appropriate approach to use:
a. while loop
b. for loop
c. if statement
d. a function
11. What is the appropriate statement to call the doCalc() method of an object called thisObj, and capturing the return value into a variable result?
a. doCalc(thisObj, x, result)
b. result = doCalc()
c. result = thisObj.doCalc(x)
d. result = thisObj.doCalc()
12. What is the output of the following code?
def main():
x=5
y=4
x=calTest(x,y)
print (y)
def calTest(y,z):
z = 4
y = int (y)
y= y*z+2*3/2
return y
main()
a. 3
b. 23
c. 13
d. 4
13. What is the output from the following code?
for i in range (-1,9,3):
print (i)
a. 1 4 7
b. 8 7 6 5 4
c. -1 2 5 8
d. -1 2 5
14. What is the output of the following code?
myDict = {2:'cat',4:'chicken',3:'dog',1: 'rabbit'}
print (myDict[3])
a. cat
b. chicken
c. dog
d. rabbit
15. What is the output of the following code?
def main():
x=5
y=3
if x > 5:
x=calTest(x,y)
elif x <= 5:
x =calTest2(x,y)
print (x)
def calTest(y,z):
z = 4
y = int (y)
y= y*z+2*3/2
return y
def calTest2 (a,b):
a = int(a)
b = int(b)
c = a+b-55+102
d = c
c = 5
return c
main()
a. 55
b. 15
c. 5
d. 7
For questions 16 and 17, use the following variable assignment:
myList = [7 , 3 , 2 , 8]
16. What is the output of:
print (myList[2])
a. 2
b. 7
c. 9
d. 3
17. What is the output of:
print (7.0 / 2.0 + 2.0 * myList[2])
a. 11
b. 9.5
c. 7
d. 7.5
18. What is the output of:
x = 10
y = 5
if x > 2 and y < 6:
print (1)
elif x < 3 and y >= 5:
print (2)
elif x >= 3 and y < 5:
print (3)
else:
print (4)
a. 1
b. 2
c. 3
d. 4
19. What is the output from the following code:
def main():
x=5
x = calTest(x)
print (x)
def calTest(y):
y = int (y)
y= y*2+2*3/2
main()
a. 6
b. 13
c. 10
d. 5
20. What is the output from the following:
myString = 'letsDoIt'
print (myString[1:-3])
a. etsD
b. tsDo
c. etsDoI
d. none of the above