Python wait | How to Python wait for input

In an application or program, sometimes you need to stop the execution of the next step or wait for a second. For example, block a user resend the OTP button for and 30 seconds. You can do Python wait by using the Python time module sleep() function.

Here you will learn about what function you can use and how to work on python wait.

Python wait | How to Python wait for input


A simple syntax for the stop a python program for a second. In the sleep() function, you have to pass the t value as seconds.


Python wait Example

Here we are importing direct sleep members from the time module, you can read this tutorial for Import from module_name.member_name.

In this example the first line print immediately but the second-line program will wait for 5 seconds.

from time import sleep

print("Start: Wait")
print("Wait is over")

Output: Start: Wait
Wait is over

Python waits for input user Input 

Here is an example where use Enter a name then program will reply in 5 seconds. You have to import a time module to use a sleep() function.

For taking an input from a user, use in-build function input.

import time

name = input('Please Enter Your Name \n')

print('Wait ', 5, 'seconds for reply.')

print('Hi', name, ', How are you, I am bot!')

Output: check this gif image file

 Python wait for input output

It can your interview question for python programming.

Do comment if you have any doubt and suggestion on this tutorial.

Note: This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

Python 3.7

All Python wait for input user Input Example is in Python 3, so it may change its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.