What is the expected output of the following code?
def func(text, num):
while num > 0:
print(text)
num = num – 1
func(‘Hello’, 3)
A . An infinite loop.
B. Hello
Hello
Hello
C. Hello
Hello
Hello
Hello
D. Hello
Hello
Answer: A
Explanation:
Topics: def while indentation
Try it yourself:
def func(text, num):
while num > 0:
print(text)
num = num – 1
func(‘Hello’, 3) # An infinite loop
The incrementation of num needs to be inside of the while loop.
Otherwise the condition num > 0 will never be False
It should look like this:
def func(text, num):
while num > 0:
print(text)
num = num – 1
func(‘Hello’, 3)
"""
Hello
Hello
Hello
"""
Latest PCEP-30-02 Dumps Valid Version with 124 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund