Ask Question
17 September, 12:05

Write a program that will prompt the user for some input, allow the user a certain amount of time to respond (e. g., 10 seconds), and if no response is provided within the allotted time, an appropriate timeout message printed on the screen.

+4
Answers (1)
  1. 17 September, 13:29
    0
    import time import threading response = None def checkAnswer () : if response! = None: time. sleep (10) return print ("/nInput time out") thread1 = threading. Thread (target=checkAnswer) thread1. start () response = input ("Enter your name: ") print ("Welcome " + response)

    Explanation:

    The solution code is written in Python 3.

    Firstly import time and threading module (Line 1 - 2). We are going to use sleep method from time module to set the interval time and also the Thread class from threading module to create a parallel running thread to check user response.

    Let's initialize response variable with None (Line 4). Next, we define a function checkAnswer (Line 6). In the function, we set time interval 10 seconds using the sleep method and create an if condition to evaluate if the response is not None simply trigger the return statement or display the message input time out (Line 7 - 10).

    Next, we create a thread to run checkAnswer function (Line 12 - 13). While the thread1 is running, prompt the user to input name and display their name (Line 15 - 16). Since the thread1 is running, if there is no response from user, the Input time out message will be displayed.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that will prompt the user for some input, allow the user a certain amount of time to respond (e. g., 10 seconds), and if no ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers