Computer Science
Predict the output of the following code.
def code(n):
if n == 0:
print ( 'Finally' )
else:
print (n)
code (3)
code (15)
Python
Python Functions
1 Like
Answer
3
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
. 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.
Answered By
2 Likes
Related Questions
Why are recursive functions considered slower than their iterative counterparts?
Compare and contrast the use of iteration and recursion in terms of memory space and speed.
Predict the output of the following code.
def code (n) : if n==0: print('Finally') else: print(n) code (2-2) code (15)
Predict the output of the following code.
def code(n): if n == 0: print(' Finally') else: print (n) code (10)