Can Python do that - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Can Python do that (/thread-7253.html) |
Can Python do that - hello_its_me - Dec-30-2017 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? RE: Can Python do that - squenson - Dec-30-2017 Yes, python can do this. Google "python event programming" or "python asynchronous programming". RE: Can Python do that - RandomCoder - Jan-07-2018 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) RE: Can Python do that - squenson - Jan-07-2018 @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. RE: Can Python do that - RandomCoder - Jan-07-2018 Um, you could still type on other programs while the python is still running, you do realize that, right? RE: Can Python do that - karaokelove - Jan-07-2018 (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. RE: Can Python do that - RandomCoder - Jan-08-2018 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. |