Slow printing - still need answers
<p>This topic has already been covered but I am still having trouble. The code I have does print the string but it prints it extremely fast. I have tried changing the time value but it doesn't seem to change anything.</p>

<p>Here is <em>everything</em> I have - Maybe I just need a more complete example?</p>

<pre><code>import sys,time,random

typing_speed = 50 #wpm
def slow_type(t):
    for l in t:
        sys.stdout.write(l)
        time.sleep(random.random()*10.0/typing_speed)
print "Tell if you think this is too fast?"
</code></pre>

<p>My problem with the existing solution(s) is I don't see how the code coerces the output to the stated WPM except by trial and error:</p>

<pre><code>time.sleep(random.random()*10.0/typing_speed)
</code></pre>

<p>and seems to get it wrong, time-wise, by more than 2X too fast.</p>

<p>If instead we use the standard definition of <em>word</em> in WPM as "five keystrokes" and the standard definition of <em>minute</em> in WPM as "sixty seconds", then "Tell if you think this is too fast?" should take ~ 8.5 seconds.  Reworking the code using the above logic, we get something like:</p>

<pre><code>import sys
import time

typing_speed = 50  # wpm

def slowprint(string):

    # the WPM system considers a word to be 5 keystrokes
    # so convert from words per minute to seconds per character
    spc = 12.0 / typing_speed  # 12.0 = 60 seconds per minute / 5 characters per word

    for character in string:
        sys.stdout.write(character)
        sys.stdout.flush()  # Force the output of everything in the buffer.

        time.sleep(spc)

    sys.stdout.write("\n")  # print a newline, because it looks cleaner.

slowprint("Tell if you think this is too fast?")
</code></pre>

python python-2.7