How to add a wait in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to add a wait in python

https://code.sololearn.com/cJ9P1xIEMZOL/?ref=app I want to add it in the lines that have nothing

15th May 2023, 1:49 AM
Finnlyn Cessna
6 Answers
+ 5
Finnlyn Cessna , > please note that sololearn playground does *not support any length of a delay by using sleep()* > in other regular python installations it will work as expected.
15th May 2023, 11:55 AM
Lothar
Lothar - avatar
+ 5
Евгений , i did not say that sololearn does not support time.sleep(). read my former post carefully. > my statement was: please note that sololearn playground does *not support any length of a delay by using sleep()* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this means that sleep(1) or 2 or 5 may work, but not sleep(10) or the sum of some smaller calls. it depends on the total time elapsed by the code while running on the sololearn server.
16th May 2023, 6:13 AM
Lothar
Lothar - avatar
+ 2
You need to import sleep from the time module. from time import sleep print('1') sleep(1) print('2') sleep(1) print('3') sleep(1) sleep takes seconds as argument, so if you want your code to wait for 10 seconds: sleep(10) I hope this helps!
15th May 2023, 2:47 AM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
You can ask the program to wait for a certain amount of seconds by using one of the libraries, in Python, which is time. Once you import the library, then you have to import a special feature in the library, in this case sleep. Here is an example: from time import sleep print("Hello") sleep(1) print("Hi") sleep(5) In the above program, the text Hello is shown after 1 second of its execution. Once the text "Hello" is presented, the program will wait for 5 seconds, and it will display the text "Hi". You have to note one thing: the waiting time is measured in seconds, not minutes, or milliseconds.
15th May 2023, 1:59 PM
Danish Zubair
Danish Zubair - avatar
0
I forgot to mention this in the earlier message, and as mentioned by Lothar, this library does not work on Sololearn. You can try to use this library in other downloadable editors, such as Visual Studio Code, Pycharm, etc.
15th May 2023, 2:02 PM
Danish Zubair
Danish Zubair - avatar
0
Finnlyn Cessna , Lothar Actually it's not correct to say that the SoloLearn Playground doesn't support sleep(). It does support it, but you won't notice its effect because of the way the Playground is implemented (non-interactive, fully buffered IO). For example if you add too much sleep()s (time-wise, not count-wise) then you will get the "No output message" because of the timeout.
15th May 2023, 9:56 PM
Евгений
Евгений - avatar