निम्नलिखित पायथन कोड का आउटपुट क्या होगा?
What will be the output of the following Python code ?
def display(b, n):
while n>0:
print(b, end=””)
n=n-1
display(‘z’, 3) A
zzz
B
zz
C
Infinite loop
D
An exception is thrown
Explanation
Let's break down the code:
def display(b, n):
while n > 0:
print(b, end="")
n = n - 1
display('z', 3)
- Function call:
display('z', 3)b = 'z'andn = 3.
- While loop: The loop runs while
n > 0. In each iteration:-
It prints
b(which is'z'). -
Decreases
nby 1. -
First iteration:
n = 3, print'z',nbecomes 2. -
Second iteration:
n = 2, print'z',nbecomes 1. -
Third iteration:
n = 1, print'z',nbecomes 0. The loop stops.
-
So, the output will be 'zzz'.
Answer: (A) zzz
Correct Answer: A) zzz