Computer Science
What will the following function print when called ?
def addEm(x, y, z):
return x + y + z
print(x + y + z)
Python Functions
4 Likes
Answer
The function addEm prints nothing when called.
Explanation
- The function
addEm(x, y, z)
takes three parameters x, y, and z. - It returns the sum of x, y, and z.
- Since the return statement is encountered first, the function exits immediately after returning the sum. The print statement after the return statement is never executed. Therefore, it prints nothing.
Answered By
2 Likes
Related Questions
Consider the following code and write the flow of execution for this. Line numbers have been given for your reference.
1. def power(b, p): 2. y = b ** p 3. return y 4. 5. def calcSquare(x): 6. a = power(x, 2) 7. return a 8. 9. n = 5 10. result = calcSquare(n) 11. print(result)
What will the following function return ?
def addEm(x, y, z): print(x + y + z)
What will be the output of following program ?
num = 1 def myfunc(): return num print(num) print(myfunc()) print(num)
What will be the output of following program ?
num = 1 def myfunc(): num = 10 return num print(num) print(myfunc()) print(num)