Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Countdown Timer…Don't know where to start

I am very very new to python and I am trying to make a simple timer app with it.
So if I input a number, like 30, the code should start counting down and output

>>> 30
>>> 29
>>> 28
>>> 27

and so on..

I am trying to get some logic into my brain. I was trying to do this since to days with same code in different places.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import time

x = input("seconds to blast off: ")
for z in range(x):
    timer.sleep(x)
print("blast off")

This is all I have written and I am stuck here.

>Solution :

Try this:

import time

sec = int(input('No. of seconds: '))
print(sec)

for s in range(sec):
    sec = int(sec) - 1
    time.sleep(1)
    if sec == 0:
        print("Blast Off")
    else:
        print(str(sec))

You got quite close to the solution.
timer.sleep() takes in the number of seconds.
Although, you could have found such answers on the web.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading