Professional Documents
Culture Documents
Quiz:Functions
Quiz:Functions
Quiz:Functions
Answer: def
// function definition (def)
2 - In Python, how do you indicate the end of the block of code that makes up the
function?
Answer: You de-indent a line of code to the same indent level as the def keyword
// The relation of dependence in statements is in base the indentation, other wise,
you code will not work in Python.
def thing():
print('Hello')
print('There')
Answer: There
// In the code the function y is defined but is never called/invoked, so only the
print is executed.
x = 'banana'
y = max(x)
print(y)
Answer: x
// The argument is the data that you pass to the function to be processed.
def func(x) :
print(x)
func(10)
func(20)
Answer: 1020
// Because is printing numbers and not string, the print does not generate a new
line.
7 - Which line of the following Python program will never execute?
def stuff():
print('Hello')
return
print('World')
def greet(lang):
if lang == 'es':
return 'Hola'
elif lang == 'fr':
return 'Bonjour'
else:
return 'Hello'
print(greet('fr'),'Michael')
Answer: Avoiding writing the same non-trivial code more than once in your program
// Avoids repetition of your code and makes it more compact.