[Type B] Working with Functions – Chapter 3 Sumita Arora
Table of Contents
10. Consider the code below and answer the questions that follow:
Python
def multiply(number1, number2):
answer = number1 * number2
print(number1, 'times', number2, '=', answer)
return answer
output = multiply(5, 5)
- When the code above is executed, what prints out?
- What is variable
output
equal to after the code is executed?
Solution:
- The code will print:
Output
5 times 5 = 25
This is because the multiply
function calculates the product of number1
and number2
and then prints the result along with the values of number1
and number2
.
- Variable
output
will be equal to the return value of themultiply
function, which is25
. The function returns the product of the two numbers.
In short, output is:
- 5 times 5 = 25
output
is equal to25
.