Computer Science

Predict the output of the following code.

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

Python

Python Functions

2 Likes

Answer

Finally
15

Working

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.

Answered By

1 Like


Related Questions