CBSE Class 12 Computer Science Question 82 of 103

Working with Functions — Question 15

Back to all questions
15
Question

Question 11

Consider the code below and answer the questions that follow :

def multiply(number1, number2):
    answer = number1 * number2
    return(answer)
    print(number1, 'times', number2, '=', answer)
output = multiply(5, 5)

(i) When the code above is executed, what gets printed ?

(ii) What is variable output equal to after the code is executed ?

Answer

(i) When the code above is executed, it will not print anything because the print statement after the return statement won't execute. Therefore, the function exits immediately after encountering the return statement.

(ii) After the code is executed, the variable output is equal to 25. This is because the function multiply returns the result of multiplying 5 and 5, which is then assigned to the variable output.