How do I run one def function inside of a different def function in python?
<p>I'm trying to run a timer inside of a function of my code. I need to start the timer slightly before the user starts typing, then stop the timer when the user has entered the alphabet correctly.
Here is my code:</p>

<pre><code>import time
timec = 0
timer = False

print("Type the alphabet as fast as possible.\nYou MUST be accurate!\nYou will be timed")
timer = True
attempt = input("The timer has started!\nType here: ")

while timer == True:
    time.sleep(1)
    timec = timec +1


if attempt == "abcdefghijklmnopqrstuvwxyz":
    timer = False
    print("you completed the alphabet correctly in", timec,"seconds!")
else:
    print("There was a mistake! \nTry again: ")
</code></pre>

<p>The issue is that it will not let me enter the alphabet. In previous attempts of this code (Which I do not have) i have been able to enter the alphabet, but the timer would not work. Any help is appreciated </p>

<p>Think carefuly about that you are dong</p>

<ol>
<li>You ask for a user-entered string</li>
<li>While <code>timer</code> equals <code>True</code>, you sleep for one second and increase the count. In this loop, you do not change the <code>timer</code>.</li>
</ol>

<p>Obviously, once user stopped entering the alphabet and pressed enter, you start an infinite loop. Thus, nothing seems to happen.</p>

<p>As other answers suggested, the best solution would be to save the time right before prompting user to enter the alphabet and compare it to the time after he finished.</p>

python function time timer