Python Forum

Full Version: Can Python do that
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,
I am writing a program that should start a timer but while the timer isn't finished there should still be the possibility to input things and get an output is something like that possible in python?
Yes, python can do this. Google "python event programming" or "python asynchronous programming".
Yes, this is the code I wrote, it displays the time left, but it only counts down with seconds, not like 1m 30s... 1m 29s, and so on.
import time
sec=0

sec = int(input("hello! To how many seconds would you lke to set your timer to?"))
sec = sec + 1
for i in reversed(range(sec)):
    print(i)
    time.sleep(1)
@RandomCoder: What the OP would like is, while the timer is counting the time, allow the user to enter some text, without stopping the timer.
Um, you could still type on other programs while the python is still running, you do realize that, right?
(Jan-07-2018, 03:01 PM)RandomCoder Wrote: [ -> ]Um, you could still type on other programs while the python is still running, you do realize that, right?

I believe he means in the same program. I ran your code (you don't need that "sec = 0", just fyi) and it does create a timer, but I can't interact with the program while it is counting down. I can still type in the console, but it has no effect on the program.

I believe what OP wants is something like a quiz program, where it might print a question and you only have 10 seconds to enter your input. I'm a noob, so I'm not sure how to accomplish this, though I imagine it would require at least one loop. I need to look into asynchronous Python, as @squensen mentioned.

[Edit] Just found this article on asynchronous programming. Starting to mess around with it right now.
Well, I did what @hello_its_me wanted, I really don't have to do more with that, i just helped @hello_its_me and that is it really.