CBSE Class 12 Computer Science Question 74 of 101

Functions — Question 42

Back to all questions
42
Question

Question 37(b)

Predict the output of the following code.

def code (n) :
    if n==0:
       print('Finally') 
    else:
       print(n)
code (2-2)
code (15)
Answer
Output
Finally
15
Explanation

The code defines a function code(n) that takes a single argument n. Inside the function, if the input n is equal to 0, it prints "Finally", otherwise, it prints the value of n. In the first function call code(2-2), the expression 2-2 evaluates to 0, so the function prints "Finally". Conversely, in the second function call code(15), the value 15 is not equal to 0, so the function prints 15.