| 2 | from essential_generators import DocumentGenerator |
| 3 | |
| 4 | def typing_speed(): |
| 5 | |
| 6 | # Generating a random sentence |
| 7 | gen = DocumentGenerator() |
| 8 | String = gen.sentence() |
| 9 | wordcount=len(String.split()) |
| 10 | |
| 11 | # Typing Speed Calculation |
| 12 | print(String) |
| 13 | print("----------------------------------------") |
| 14 | startTime=time.time() |
| 15 | textInput=str(input("Type the sentence: " )) |
| 16 | endTime=time.time() |
| 17 | accuracy= len(set(textInput.split())&set(String.split())) |
| 18 | accuracy=accuracy/wordcount*100 |
| 19 | timeTaken=round(endTime-startTime,2) |
| 20 | wpm=round((wordcount/timeTaken)*60) |
| 21 | print("----------------------------------------") |
| 22 | |
| 23 | # Showing the results |
| 24 | print ("Your accuracy is: ", accuracy) |
| 25 | print ("Time taken: ", timeTaken, "seconds") |
| 26 | print("Your typing speed is: ",wpm,"words per minute") |
| 27 | |
| 28 | if accuracy < 50 or wpm < 30: |
| 29 | print("You need to practice typing more!") |
| 30 | elif accuracy < 80 or wpm < 60: |
| 31 | print("You are doing great!") |
| 32 | elif accuracy <= 100 or wpm <= 100: |
| 33 | print("You are a pro in typing!") |
| 34 | else: |
| 35 | print("You are a typing machine!") |
| 36 | |
| 37 | |
| 38 | if __name__ == "__main__": |