Ask 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 response is provided within the allotted time, an appropriate timeout message printed on the screen.

+3
Answers (1)
  1. 3 June, 09:46
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers