Answer the question
In order to leave comments, you need to log in
How to make a specific response time in Python?
My code asks the question:
The user must answer 1-yes, 2-noprint ('Газон зеленый')
print ('1 - Правда')
print ('2 - Ложь')
print ('Газон зеленый')
print ('1 - Правда')
print ('2 - Ложь')
ans = int(input('Ваш вариант ответа:'))
time.sleep (10)
print ('Время вышло!')
if ans == 1:
print ('Вы ответили правильно!')
elif ans == 2:
print ('Вы ответили не правильно!')
else:
print ('Вы не ответили')
(time.sleep (10))
Answer the question
In order to leave comments, you need to log in
Works but needs to be improved
import time
from threading import Thread
an = 1
ans = 0
def countdown():
time.sleep (10)
if not ans:
print ('\nВремя вышло!')
global an
an = 0
def answer():
global ans
ans = int(input('Ваш вариант ответа:'))
if ans == 1 and an:
print ('Вы ответили правильно!')
elif ans == 2 and an:
print ('Вы ответили не правильно!')
else:
ans = 3
print ('Вы не ответили')
print ('Газон зеленый')
print ('1 - Правда')
print ('2 - Ложь')
task1 = Thread(target=countdown)
task2 = Thread(target=answer)
task1.start()
task2.start()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question