-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject 3.py
More file actions
38 lines (33 loc) · 1.02 KB
/
Project 3.py
File metadata and controls
38 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Typing speed test game
from random import randint
import time
sentences = [
"One day , I wake up early morning and saw that dogs were baking.",
"Honesty is the best policy.",
"Python is the best language to learn for coding.",
"This game is created by Ajay Kumar Jakhar, student of IIT Madras and NIT Kurukshetra.",
"This game is created in python language and complied in Macbook Air M2."
]
def calculate_wpm(time, words):
minutes = time /60
wpm = words / minutes
return wpm
print("Get ready to type this sentence: ")
sentence = sentences[randint(0,4)]
print(sentence)
time.sleep(1)
print("in 3,", end=" ")
time.sleep(1)
print("2,", end=" ")
time.sleep(1)
print("1 go!")
start_time = time.time()
user_input = input()
end_time = time.time()
if user_input == sentence:
#calculate the wpm
words = len(sentence.split())
wpm = calculate_wpm(end_time - start_time, words)
print("Your typing speed is ", wpm, "wpm")
else :
print("The input does not match the sentence, please try again!!")