Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#iport libraries
|
| 2 |
+
import time
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# Some sentences to test typing speed
|
| 6 |
+
sentences = [
|
| 7 |
+
"Python is a great programming language",
|
| 8 |
+
"Artificial Intelligence is the future",
|
| 9 |
+
"Machine learning makes computers intelligent",
|
| 10 |
+
"Typing speed test game is fun to play",
|
| 11 |
+
"Data science is changing the world"
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
# Pick random sentence
|
| 15 |
+
sentence = random.choice(sentences)
|
| 16 |
+
print("\n💻 Type this sentence as fast as you can:\n")
|
| 17 |
+
print("👉", sentence)
|
| 18 |
+
print()
|
| 19 |
+
|
| 20 |
+
# Start typing
|
| 21 |
+
input("Press Enter when you are ready to start...\n")
|
| 22 |
+
start_time = time.time()
|
| 23 |
+
typed = input("Start Typing: \n")
|
| 24 |
+
end_time = time.time()
|
| 25 |
+
|
| 26 |
+
# Calculate speed and accuracy
|
| 27 |
+
time_taken = round(end_time - start_time, 2)
|
| 28 |
+
words = sentence.split()
|
| 29 |
+
typed_words = typed.split()
|
| 30 |
+
|
| 31 |
+
correct = 0
|
| 32 |
+
for i in range(min(len(words), len(typed_words))):
|
| 33 |
+
if words[i] == typed_words[i]:
|
| 34 |
+
correct += 1
|
| 35 |
+
|
| 36 |
+
accuracy = round((correct / len(words)) * 100, 2)
|
| 37 |
+
wpm = round(len(typed_words) / (time_taken / 60))
|
| 38 |
+
|
| 39 |
+
print("\n⏱️ Time Taken:", time_taken, "seconds")
|
| 40 |
+
print("✅ Accuracy:", accuracy, "%")
|
| 41 |
+
print("⚡ Your Typing Speed:", wpm, "words per minute (WPM)")
|
| 42 |
+
|