File tree Expand file tree Collapse file tree
utilities/Typing-Speed-Tester Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7070 # Calculate time
7171 time_taken = end_time - start_time
7272
73- # Calculate words per minute
74- words = len (sentence .split ())
75- wpm = (words / time_taken ) * 60 if time_taken > 0 else 0
73+ # Calculate words per minute based on typed text
74+ sentence_words = sentence .split ()
75+ typed_words = typed_text .split ()
76+ correct_words = sum (
77+ 1 for i , word in enumerate (typed_words )
78+ if i < len (sentence_words ) and word == sentence_words [i ]
79+ )
80+ wpm = (correct_words / time_taken ) * 60 if time_taken > 0 else 0
7681
7782 # Calculate accuracy
7883 correct_chars = 0
8590 # Results
8691 print ("\n 🎉 ===== TEST COMPLETED ===== 🎉" )
8792 print (f"⏱️ Time Taken : { time_taken :.2f} seconds" )
88- print (f"🚀 Typing Speed : { wpm :.2f} WPM" )
93+ print (f"🚀 Net WPM : { wpm :.2f} WPM" )
8994 print (f"🎯 Accuracy : { accuracy :.2f} %" )
9095
9196 # Performance feedback
You can’t perform that action at this time.
0 commit comments