+ 2
Is there a way in python to PAUSE the code at any given time?
For example, print(“Hi”) Wait 5 seconds… print(“Hey”) And if so, can you make it so that instead of inserting input at the beginning of a code, you can do it somewhere in the middle? For example print(“Hi”) print(“Is your name “ + input() + “?”) But instead of putting the input in the beginning, it’s at the middle? In case you didn’t see, this is python.
10 Antworten
+ 3
It dosen t work on sololearn compiler, try on termux or pydroid
+ 2
import time
print("Hi")
time.sleep(5) #wait 5 sec
print("Hey")
on sololearn it will happen on the server side, you'll not notice it.
+ 1
You can't see the delay, but it does happen.
What if you print the current time, delay for some time, print the current time again. I think you will see the two prints on SoloLearn, but it may time out if your delay is too long....
EDIT: I think code playground executes without time... magic! gives a single value when DELAY is 4, crashes at DELAY is 5.
https://code.sololearn.com/cR7blxSM96l2/?ref=app
+ 1
HungryTradie your idea works with python.
import time
print(time.time())
time.sleep(5) #wait 5 sec
print(time.time())
it prints different timestamps. 5 sec apart.
0
Also for the wait function i tried using
time.sleep
But that just made it wait in the begining instead of the middle.
0
Oh ok
0
But for the input thing can you do it later in the code or not?
0
In sololearn, Output is not live so the following will not work in sololearn :
import time
time.sleep(time to wait in seconds)
0
Impossible in Sololearn