I'm practicing creating classes and functions in Python. In a certain simple countdown exercise, I had to use the sleep()
function inside a FOR
loop to display the numbers one by one. The issue is that the output performs the count, but without showing the number corresponding to the thread of the FOR
loop. In the end, the numbers appear all at once in a single print. The code is below:
import closed
from time import sleep
class Countdown:
def __init__(self):
pass
def Count(self):
for counter in range(10,-1,-1):
print(f'{counter} ', end='')
sleep(1)
return 'Finished Counting!'
countdown = Countdown()
print(countdown.Count())
Just to inform you, import closed
only serves to show a thank you message at the beginning of the program execution.
I tried taking the FOR
loop from the Count
method and putting it in the class call in the main part of the code below, but I got the same behavior. Thanks in advance for the responses.