Skip to content

Commit 70852e2

Browse files
Update PykitDreams.py
1 parent beb8761 commit 70852e2

File tree

1 file changed

+38
-58
lines changed

1 file changed

+38
-58
lines changed

1.0/PykitDreams.py

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from tkinter import *
33
from math import *
44
from numpy import *
5+
from wonderwords import RandomSentence
6+
import time
57
import sys
68
import turtle
79
import random
@@ -95,67 +97,45 @@ def click(self, b_text):
9597
root.mainloop()
9698

9799
def typingtest():
98-
from time import time
99-
100-
def typingErrors(prompt):
101-
global iwords
102-
words = prompt.split() + [' ' for _ in range(len(iwords) - len(prompt.split()) + 1)]
103-
print(len(words))
104-
print(len(iwords))
105-
errors = 0
106-
for i in range(len(iwords) - 1):
107-
print(i)
108-
if iwords[i] == words[i+1]:
109-
iwords.insert(i, ' ')
110-
print(iwords)
111-
errors += 1
112-
continue
113-
elif iwords[i] == words[i-1]:
114-
del(iwords[i-1])
115-
print(iwords)
116-
errors += 1
117-
continue
118-
if i in (0, len(iwords)-1):
119-
if iwords[i] == words[i]:
120-
continue
121-
else:
122-
errors +=1
123-
else:
124-
if iwords[i] == words[i]:
125-
if (iwords[i+1] == words[i+1]) and (iwords[i-1] == words[i-1]):
126-
continue
127-
else:
128-
errors += 1
129-
else:
130-
errors += 1
131-
return errors
132-
133-
def typingSpeed(iprompt, stime, etime):
134-
global iwords
135-
iwords = iprompt.split()
136-
speed = len(iwords) / float(timeElapsed(stime, etime)/60)
137-
return speed
138-
139-
def timeElapsed(stime, etime):
140-
return etime - stime
141-
142-
if __name__ == '__main__':
143-
prompt = "\n\nA turquoise-blue stream wound its merry way through the forest. Babbling and burbling, it sprung over the limestone rocks in its way. Pebbles whisked about in the under wash like pieces of glitter. Streams are the liquid soul of the forest, and this one was glowing. Chords of soft light speared down from above, bathing its surface in gold. It was glinting with little sparkles, like a thousand diamonds blessed with an inner fire. A galaxy of dragonflies fizzed through the beams of light, wings a-glitter in the sun."
144-
print("TYPE THIS: ", prompt,"")
145-
input("\nPress 'Enter' when you are ready!")
146-
147-
stime = time()
148-
iprompt = input()
149-
etime = time()
100+
sent_list = []
101+
sent_para = ""
102+
for i in range(5):
103+
sent = RandomSentence()
104+
random_sent = sent.sentence()
105+
sent_list.append(random_sent)
106+
sent_para += random_sent + " "
107+
108+
def errorrate(sent_para, typed_para):
109+
errorcount = 0
110+
length = len(sent_para)
111+
for character in range(length):
112+
try:
113+
if sent_para[character] != typed_para[character]:
114+
errorcount += 1
115+
except:
116+
errorcount += 1
117+
errorpercent = errorcount/length * 100
118+
return errorpercent
150119

151-
time = round(timeElapsed(stime, etime), 2)
152-
speed = round(typingSpeed(iprompt, stime, etime), 2)
153-
errors = typingErrors(prompt)
120+
print("Your typing test paragraph: \n")
121+
print(sent_para)
122+
print("\n")
123+
start_time = time.time()
124+
typed_para = input()
125+
end_time = time.time()
126+
time_taken = end_time - start_time
127+
errorpercent = errorrate(sent_para, typed_para)
128+
print("\n")
154129

155-
print("Total time elapsed:", time, "s")
156-
print("Mean typing speed:", speed, "words/minute")
157-
print("With a total of:", errors, "errors")
130+
if errorpercent > 35:
131+
print(f"Your error rate {error_percent} was fairly high, hence your accurate speed could not be computed.")
158132

133+
else:
134+
speed = len(typed_para)/time_taken
135+
print("Score Report: ")
136+
print(f"Your typing speed was {speed} words/second.")
137+
print(f"Your error rate was {errorpercent}.")
138+
159139
def tictactoe():
160140
pygame.init()
161141
WIDTH = 600

0 commit comments

Comments
 (0)