|
2 | 2 | from tkinter import * |
3 | 3 | from math import * |
4 | 4 | from numpy import * |
| 5 | +from wonderwords import RandomSentence |
| 6 | +import time |
5 | 7 | import sys |
6 | 8 | import turtle |
7 | 9 | import random |
@@ -95,67 +97,45 @@ def click(self, b_text): |
95 | 97 | root.mainloop() |
96 | 98 |
|
97 | 99 | 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 |
150 | 119 |
|
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") |
154 | 129 |
|
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.") |
158 | 132 |
|
| 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 | + |
159 | 139 | def tictactoe(): |
160 | 140 | pygame.init() |
161 | 141 | WIDTH = 600 |
|
0 commit comments