umerfarooq29's picture
Create app.py
cdec65b verified
#iport libraries
import time
import random
# Some sentences to test typing speed
sentences = [
"Python is a great programming language",
"Artificial Intelligence is the future",
"Machine learning makes computers intelligent",
"Typing speed test game is fun to play",
"Data science is changing the world"
]
# Pick random sentence
sentence = random.choice(sentences)
print("\n💻 Type this sentence as fast as you can:\n")
print("👉", sentence)
print()
# Start typing
input("Press Enter when you are ready to start...\n")
start_time = time.time()
typed = input("Start Typing: \n")
end_time = time.time()
# Calculate speed and accuracy
time_taken = round(end_time - start_time, 2)
words = sentence.split()
typed_words = typed.split()
correct = 0
for i in range(min(len(words), len(typed_words))):
if words[i] == typed_words[i]:
correct += 1
accuracy = round((correct / len(words)) * 100, 2)
wpm = round(len(typed_words) / (time_taken / 60))
print("\n⏱️ Time Taken:", time_taken, "seconds")
print("✅ Accuracy:", accuracy, "%")
print("⚡ Your Typing Speed:", wpm, "words per minute (WPM)")