Computer Science
What is wrong with the following function definition ?
def addEm(x, y, z):
return x + y + z
print("the answer is", x + y + z)
Python Functions
6 Likes
Answer
In the above function definition, the line print("the answer is", x + y + z)
is placed after the return statement. In python, once a return statement is encountered, the function exits immediately, and any subsequent code in the function is not executed. Therefore, the print statement will never be executed.
Answered By
2 Likes
Related Questions
What will be the output of following program ?
def display(): print("Hello", end='') display() print("there!")
Predict the output of the following code :
a = 10 y = 5 def myfunc(): y = a a = 2 print("y =", y, "a =", a) print("a + y =", a + y) return a + y print("y =", y, "a =", a) print(myfunc()) print("y =", y, "a =", a)
Write a function namely fun that takes no parameters and always returns None.
Consider the code below and answer the questions that follow :
def multiply(number1, number2): answer = number1 * number2 print(number1, 'times', number2, '=', answer) return(answer) output = multiply(5, 5)
(i) When the code above is executed, what prints out ?
(ii) What is variable output equal to after the code is executed ?