+ 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.

13th Feb 2022, 3:37 PM
The Coder
The Coder - avatar
10 ответов
+ 3
It dosen t work on sololearn compiler, try on termux or pydroid
13th Feb 2022, 3:56 PM
Sebastian RSA
Sebastian RSA - avatar
+ 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.
13th Feb 2022, 3:58 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 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
13th Feb 2022, 9:41 PM
HungryTradie
HungryTradie - avatar
+ 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.
14th Feb 2022, 1:06 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
Also for the wait function i tried using time.sleep But that just made it wait in the begining instead of the middle.
13th Feb 2022, 3:39 PM
The Coder
The Coder - avatar
0
Oh ok
13th Feb 2022, 4:42 PM
The Coder
The Coder - avatar
0
But for the input thing can you do it later in the code or not?
13th Feb 2022, 4:42 PM
The Coder
The Coder - avatar
0
In sololearn, Output is not live so the following will not work in sololearn : import time time.sleep(time to wait in seconds)
15th Feb 2022, 11:51 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
0
Impossible in Sololearn
15th Feb 2022, 11:52 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar