So I’m trying to build a simple typing speed test. It takes the input for 60 seconds and calculates typing speed and accuracy. I used “inputimeout” to try achieve the objectives, however, the variable “text”, which should contain the timed input from the user, cannot be used in other parts of the program; it causes an error stating that “text” was not assigned.
This is just one part of the code. This should be where the error is
def text_receiver():
try:
text = inputimeout(prompt = "Type the above in one minute: ", timeout = 60)
except Exception:
print("Time's up! ")
return text
This is the error
local variable 'text' referenced before assignment
if the error is quite obvious, I apologize as I haven’t written much codes with “try except” and inputimeout
Esandu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.