Test
CS 1101 Week 4
Preguntas del test (14)
1One of the advantages of a function is that it allows the programmer to alter the flow of the execution in the program
- AVerdadero
- BFalso
2A stack diagram shows the value of each variable and the function to which each variable belongs
- AVerdadero
- BFalso
3The graphical representation of a stack of functions, their variables, and the values to which they refer is called a traceback.
- AVerdadero
- BFalso
4A local variable is a variable defined inside a function that can only be used inside its function.
- AVerdadero
- BFalso
5What will the output of this python program be?
def test_function(length, width, height):
print ("the area of the box is ",length*width*height)
return length*width*height
l = 12.5
w = 5
h = 2
test_function(l,w,h)- AThe area of the box is 125
- BThe area of the box is 125.0
- CThe area of the box is 120
- D125.0
6What will the output of this program be when it is executed?
def test_function( length, width, height):
print ("the area of the box is ", length*width*height)
return length*width*height
l = 12.5
w = 5
h = 2
test_function(l, w, h)
print ("The area of the box is ", length*width*height)- AA NameError because a variable is not defined
- BThe area of the box is 125.0
- CThe are of the box is 0
- DA SyntaxError due to illegal function call
7What will the output of the following code be?
def recursive( depth ):
depth+=1
while (depth < 5):
ret = recursive(depth)
return depth
ret = recursive( 0 )
print ("the recursive depth is ", ret)- AThe recursive depth is 5
- BThe recursive depth is 4
- CError due to depth of recursive calls
- DNone
8What will the output of the following program be?
i=0
while (i < max(1, 22-4*5, 3*5-3*4, 2**2)):
i+=1
print (i)- A0
- B5
- C3
- D4
9What output will the following Python script produce?
def function2(param):
print (param, param)
def function1(part1, part2):
cat = part1 + part2
function2(cat)
chant1 = "See You"
chant2 = "See Me"
function1(chant1, chant2)- ASee You See Me
- BSee You See Me See You See Me
- CSee Me See Me See You See You
- DNone it would generate an error
10What does the import statement in the following script do?
import StringIO
output = StringIO.StringIO()
output.write('First line.\n')
output.close()- AIt imports data into the script
- BIt changes the format of the string in the script
- CIt opens a file for StringIO functions to read
- DIt includes a Python module called StringIO into the script
11The following Python script will generate an error when executed. What is the cause of the error?
def function2(param):
print (param, param)
print (cat)
def function1(part1, part2):
cat = part1 + part2
function2(cat)
chant1 = "See You"
chant2 = "See Me"
function1(chant1, chant2)- AThe variable cat is local to function1 and cannot be used in function 2
- BThe variable param is used twice in function2 and this is illegal
- CFunction2 does not have a return value defined
- DFunction1 does not have a return value defined
12Dot notation is reserved for variable names and cannot be used to call a function
- AVerdadero
- BFalso
13Functions always get executed first regardless to the flow of execution
- AVerdadero
- BFalso
14The 80286 microprocessor was introduced in Feb '82 and was four times more powerful than the 8088
- AVerdadero
- BFalso
Información
- Descripción
- El usuario ha eliminado su información de asignaturas Test sobre CS 1101 Week 4 , creado por Usuario eliminado el 22/09/2016.
- Autor
- Usuario eliminado
- Idioma
- English
- Visitas
- 47
- Historial
- Creado el 22 sep 2016 · actualizado el 15 nov 2016
- Etiquetas