import nltk
import time
from nltk.corpus import brown
nltk.download('brown')

import random
from difflib import SequenceMatcher


k = ''
randi = random.randint(1,len(brown.words()))
randsent = brown.words()[randi:]
    
count = 0    
for i, w in enumerate(randsent):
    k += w 
    if '.' not in w:
        k += ' '
    if '.' in w:
        if count != 0:
            print('')
            print('Type this sentence for speed and accuracy:')
            print('')
            print(f"{k.split(' .')[0]}.")
            print('')
            print(3)
            time.sleep(1)
            print(2)
            time.sleep(1)
            print(1)
            time.sleep(1)
            print('Go!')
            time1 = time.time()
            x = input() 
            time2 = time.time()    
            time3 = time2-time1

            wordcount = len(k.split(' '))
            wpm = wordcount/(time3/60)
            print(f"words per minute {wpm:.2f}")

            sim_ratio = 100*SequenceMatcher(None, k, x).ratio()

            print(f"percent accuracy: {sim_ratio:.2f}%")

        k = ''

        count += 1
