PM SHRI Kendriya
Vidyalaya
Tatanagar
COMPUTER SCIENCE:
INVESTIGATORY
PROJECT
-Azfer Kamal & Chinmay
Certificate
This is to certify that Master Azfer Kamal and
Master Chinmay have completed this project under the
supervision and guidance of Mr Babulal Hansda in the
session of 2024-25
Typehard : typing speed test
import time
import random
import os
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
users={}
current_user = ''
scores={}
high_score = 0
def error():
cls()
print("\n\nNo choice made. Please press (1) to continue\n")
print("-----Menu(1)-----")
try:
choice = int(input())
if choice == 1:
menu()
else:
print("invalid choice...")
error()
except:
error()
def register():
cls()
print("\n\n----Register----")
un = input("Enter Username - ")
ps = input("Enter Password - ")
conf_ps = input("Confirm Password - ")
if conf_ps != ps :
while conf_ps != ps :
print("password does not match")
ps = input("Enter Password - ")
conf_ps = input("Confirm Password - ")
users[un]=ps
print("Register Successful")
print("Account Created :D\n")
login()
def login():
cls()
global current_user
print("\n\n----Login----")
usercheck = input("Enter Username - ")
pscheck = input("Enter Password - ")
if usercheck not in users:
print("Account does not exist!\n Please try again")
print("Try again(1) Register(2)")
try:
ans2 = int(input(""))
if ans2 == 1:
login()
elif ans2 == 2:
register()
except:
print("No choice made.")
error()
elif usercheck in users and pscheck != users[usercheck]:
while pscheck != users[usercheck]:
print("Password does not match")
pscheck = input("Enter Password - ")
if pscheck == users[usercheck]:
print("Login successful :D")
elif usercheck in users and pscheck == users[usercheck]:
print("Login successful :D")
current_user = usercheck
menu()
def Titlescreen():
cls()
print("\n\n")
print("------------------------------------------------------")
print("\n")
print('''
|| || ||
| |_ _ _ _ __ ___| |__ __ _ _ __ __| |
| __| | | | '_ \ / _ \ '_ \ / _` | '__/ _` |
| |_| |_| | |_) | __/ | | | (_| | | | (_| |
\__|\__, | .__/ \___|_| |_|\__,_|_| \__,_|
__/ | |
|___/|_| ''')
print("\n\n")
print("-----Register(1)---------Login(2)---------Exit(3)-----\n")
try:
ans1 = int(input())
print("")
if ans1 == 1:
register()
elif ans1 == 2:
login()
elif ans1 == 3:
Titlescreen_exit()
else:
print("invalid answer...")
Titlescreen()
except:
error()
#print(users)
def Titlescreen_exit():
cls()
print("\n\nExiting will delete all data.\n Are you sure you want to exit?\n
------Yes(1)------------No(2)------")
choice = int(input())
try:
if choice == 2:
Titlescreen()
elif choice == 1:
print("exiting...")
return
else:
print("invalid answer")
Titlescreen_exit()
except:
print("No choice made.")
error()
def menu():
cls()
print("\n\n")
print("------------------------------------------------------------------------")
print("\n")
print('''
|| || ||
| |_ _ _ _ __ ___| |__ __ _ _ __ __| |
| __| | | | '_ \ / _ \ '_ \ / _` | '__/ _` |
| |_| |_| | |_) | __/ | | | (_| | | | (_| |
\__|\__, | .__/ \___|_| |_|\__,_|_| \__,_|
__/ | |
|___/|_|''')
print("\n\n")
print("-----Start Typing test(1)---------View Scores(2)---------Log out(3)-----\n")
choice = int(input())
try:
if choice == 1:
test_start()
elif choice == 2:
viewscore()
menu()
elif choice == 3:
Titlescreen()
else:
print("invalid choice...")
menu()
except:
print("No choice made.")
error()
def viewscore():
cls()
print("\n\n")
print("------------------------------------------------------------------")
print("\n")
print("SCORES:\n")
print(f"High Score : {high_score}\n")
print("Scores: \n")
scorelist = scores.items()
for i in scorelist:
print (i)
x = input()
def test():
cls()
print("\n\n")
print("------------------------------------------------------------------")
print("\n\n")
global high_score
words = ["the", "sun", "rises", "in", "east", "every", "morning", "cats", "are",
"curious", "creatures", "that", "love", "to", "explore", "water", "flows",
"downhill", "towards", "ocean", "birds", "sing", "beautiful", "songs",
"early", "dawn", "trees", "provide", "shade", "and", "shelter", "for",
"many", "animals", "flowers", "bloom", "spring", "with", "vibrant",
"colors", "wind", "whispers", "through", "tall", "grass", "rain", "falls",
"gently", "on", "roof", "at", "night", "butterflies", "flutter", "from",
"flower", "river", "winds", "its", "way", "valley", "mountains", "stand",
"proud", "and", "majestic", "over", "forest", "deer", "graze", "silently",
"in", "meadow", "the", "sky", "is", "clear", "and", "blue", "as", "the",
"day", "begins", "fresh", "breeze", "carries", "scents", "of", "pine",
"and", "earth", "waves", "crash", "against", "the", "shore", "in", "a",
"steady", "rhythm", "snow", "covers", "the", "ground", "in", "a", "soft",
"white", "blanket", "the", "path", "through", "woods", "is", "quiet",
"and", "serene", "clouds", "drift", "lazily", "across", "the", "sky"]
sentence_length = random.randint(10,20)
sentence = " ".join(random.choice(words) for _ in range(sentence_length))
print("\nType the following sentence:")
print(sentence)
print("\n-----Press Enter to start-----\n")
input("")
# Start the timer
start_time = time.time()
# Get user input
typed_sentence = input("Start typing: \n")
# End the timer
end_time = time.time()
# Calculate the time taken
time_taken = end_time - start_time
# Split the sentences into words
original_words = sentence.split()
typed_words = typed_sentence.split(" ")
# Count the number of correctly typed words and characters
correct_words = 0
for i in range(min(len(original_words), len(typed_words))):
if original_words[i] == typed_words[i]:
correct_words = correct_words + 1
correct_char = 0
for i in range(min(len(original_words), len(typed_words))):
for j in range(min(len(original_words[i]),len(typed_words[i]))):
if original_words[i][j] == typed_words[i][j]:
correct_char = correct_char + 1
# Calculate words per minute (WPM) based on correctly typed words
cpm = (correct_char / time_taken) * 60
wpm = (correct_words/ time_taken) * 60
# Calculate accuracy
stripped_sentence = sentence.replace(" ","")
accuracy = (correct_char / len(typed_sentence.replace(" ",""))) * 100
# Display results
print("\nResults:")
print(f"Time Taken: {time_taken:.2f} seconds")
print(f"Words Per Minute (WPM): {wpm:.2f}")
print(f"Characters Per Minute (CPM): {cpm:.2f}")
print(f"Accuracy: {accuracy:.2f}%")
print(f"Correctly Typed Words: {correct_words}/{len(original_words)}")
print(f"Correctly Typed Characters: {correct_char}/{len(stripped_sentence)}\n")
if wpm > high_score:
high_score = (wpm//(0.01))/100
print("NEW HIGH SCORE!!!\n")
scores[current_user] = f"WPM : {wpm:.2f} , Accuracy : {accuracy:.2f}"
print("-------------------------------------------------------------------------------------\n")
print("-----Retest(1)---------View Scores(2)---------Menu(3)-----\n")
try:
choice = int(input())
if choice == 1:
test()
elif choice == 2:
viewscore()
test_start()
elif choice == 3:
menu()
else:
print("invalid choice...")
test_start()
except:
print("No choice made.")
error()
def test_start():
cls()
global high_score
print("\n\n")
print(''' ____ _ _ __ _ __
/ ___|| |_ __ _ _ __| |_ / / / | \ \
\___ \| __/ _` | '__| __| | | | | | |
___) | || (_| | | | |_ | | | | | |
|____/ \__\__,_|_| \__| | | |_| | |
\_\ /_/ \n\n''')
print("-----View Scores(2)---------Menu(3)-----\n")
try:
choice = int(input())
if choice == 1:
pass
elif choice == 2:
viewscore()
test_start()
elif choice == 3:
menu()
else:
print("invalid choice...")
test_start()
test()
except:
print("No choice made.")
error()
Titlescreen()