CS 1400 EXAM 2 QUESTIONS WITH VERIFIED
ANSWERS
___ addVals(val 1, val 2)
return val 1, val 2
what's missing - Answers - def
if a function definition has the keyword return in it then it can't be a void function -
Answers - False
void function - Answers - does not have a return value
it can call return but have nothing after it so nothing returns
myFunc(val1=5, val2="Hello")
this is an example of calling a function using - Answers - keywords
when a function is called the actual parameters are pass to the function. python uses an
approach called Pass By - Answers - Value
three main purposes of using functions - Answers - make code simpler
organize code
reuse the same code
what is another term for parameters of a function when it is called - Answers -
arguments
modules - Answers - another name for files
naming convention is all lower case
2 main purposes for modules - Answers - code organization easier so it's easier to fix or
debug
it's easy to reuse
is this a valid way to call a function that has default arguments
result = addManyNum(val1 = 2, val3= 10, 40) - Answers - False
where are default arguments specified for a function - Answers - as a formal parameter
, if a function is called with parameters that do not include any keywords then the function
call only uses ___________ actual parameters - Answers - positional
a _____________ stores parameters and local variables and is a part of the program
execution management when a function is called - Answers - activation record
A _________ is a template or blueprint that is used to create an __________ of the
same type. - Answers - class , object
A __________ is used to create an instance of a class - Answers - constructor
Class A:
def _int_(self):
self.x = 1
self.__y = 2
def getY(self):
return self.__y
a= A()
print(a.__y)
what's printed - Answers - nothing bc Y is private
function vs method - Answers - functions:
defined inside a file
no required parameters
called as a stand alone code
custom data passed in a parameter
methods:
defined in a class
first parameter must be self
called after an access operator on an object
custom data obtained from instance variables and or parameters
_________ is way to diagram classes to give a visual representation - Answers - UML
unified modeling language
Encapsulation and abstraction - Answers - separation of class implementation from the
use of a class
the implementation details are hidden from user
the user knows what the result is but not how it happens
ANSWERS
___ addVals(val 1, val 2)
return val 1, val 2
what's missing - Answers - def
if a function definition has the keyword return in it then it can't be a void function -
Answers - False
void function - Answers - does not have a return value
it can call return but have nothing after it so nothing returns
myFunc(val1=5, val2="Hello")
this is an example of calling a function using - Answers - keywords
when a function is called the actual parameters are pass to the function. python uses an
approach called Pass By - Answers - Value
three main purposes of using functions - Answers - make code simpler
organize code
reuse the same code
what is another term for parameters of a function when it is called - Answers -
arguments
modules - Answers - another name for files
naming convention is all lower case
2 main purposes for modules - Answers - code organization easier so it's easier to fix or
debug
it's easy to reuse
is this a valid way to call a function that has default arguments
result = addManyNum(val1 = 2, val3= 10, 40) - Answers - False
where are default arguments specified for a function - Answers - as a formal parameter
, if a function is called with parameters that do not include any keywords then the function
call only uses ___________ actual parameters - Answers - positional
a _____________ stores parameters and local variables and is a part of the program
execution management when a function is called - Answers - activation record
A _________ is a template or blueprint that is used to create an __________ of the
same type. - Answers - class , object
A __________ is used to create an instance of a class - Answers - constructor
Class A:
def _int_(self):
self.x = 1
self.__y = 2
def getY(self):
return self.__y
a= A()
print(a.__y)
what's printed - Answers - nothing bc Y is private
function vs method - Answers - functions:
defined inside a file
no required parameters
called as a stand alone code
custom data passed in a parameter
methods:
defined in a class
first parameter must be self
called after an access operator on an object
custom data obtained from instance variables and or parameters
_________ is way to diagram classes to give a visual representation - Answers - UML
unified modeling language
Encapsulation and abstraction - Answers - separation of class implementation from the
use of a class
the implementation details are hidden from user
the user knows what the result is but not how it happens