CBSE Class 12 Computer Science Question 73 of 101

Functions — Question 41

Back to all questions
41
Question

Question 37(a)

Predict the output of the following code.

def code(n):
    if n == 0:
       print ( 'Finally' ) 
    else:
       print (n)
code (3)
code (15)
Answer
Output
3
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. When called with code(3), it passes the argument 3 to the function. Since 3 is not equal to 0, the function prints 3. Similarly, calling code(15) prints 15 as it also doesn't meet the condition for 0.