0

I want to count the number of 5s the user can input in 5 seconds. The prompt must be interrupted after 5 seconds. Here, the user will not have a chance to press the Enter key to close the prompt. Is there any way to count the number of 5s the user entered without actually the enter key being pressed?

R06
  • 47
  • 3

1 Answers1

0

The input() function requires you to press enter to confirm the input, so that wouldn't work for you. If you're using Windows, you could try the msvcrt module, as highlighted in this question's answers.

The general idea would be to loop for five seconds calling the getch() function repeatedly.

If not on Windows, there were some other answers with cross-platform solutions, such as the curses package.

Gabriel Jablonski
  • 854
  • 1
  • 6
  • 17