0% found this document useful (0 votes)
10 views2 pages

Code Time 212

The document is a Python script for a typing game called 'Type Racer' where players race against themselves to improve typing speed and accuracy. It includes features such as a welcome screen, countdown timer, random sentence selection, and calculation of words per minute (WPM), accuracy, and errors. The main menu allows users to play the game, view information about it, or exit.

Uploaded by

t.vd.leije
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Code Time 212

The document is a Python script for a typing game called 'Type Racer' where players race against themselves to improve typing speed and accuracy. It includes features such as a welcome screen, countdown timer, random sentence selection, and calculation of words per minute (WPM), accuracy, and errors. The main menu allows users to play the game, view information about it, or exit.

Uploaded by

t.vd.leije
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import time

import random
import os

sentences = [
"The quick brown fox jumps over the lazy dog.",
"Python is a great programming language for beginners and experts.",
"Artificial intelligence is transforming the way we live and work.",
"Typing fast and accurately is a valuable skill in the digital age.",
"Never gonna give you up, never gonna let you down.",
"Sphinx of black quartz, judge my vow.",
"Pack my box with five dozen liquor jugs.",
"A journey of a thousand miles begins with a single step.",
"All that glitters is not gold.",
"Time flies like an arrow; fruit flies like a banana."
]

def clear_screen():
os.system("cls" if os.name == "nt" else "clear")

def welcome():
clear_screen()
print("┌────────────────────────────────────┐")
print("│ 🧠 TYPE RACER 🏁 │")
print("└────────────────────────────────────┘")
input("Press Enter to start...")

def countdown():
for i in range(3, 0, -1):
clear_screen()
print(f"Starting in {i}...")
time.sleep(1)

def choose_sentence():
return random.choice(sentences)

def calculate_wpm(start, end, text, typed):


time_elapsed = end - start
words = len(text.split())
errors = sum(1 for a, b in zip(text, typed) if a != b) + abs(len(text) -
len(typed))
wpm = (words / time_elapsed) * 60
accuracy = max(0, (len(text) - errors) / len(text)) * 100
return round(wpm, 2), round(accuracy, 2), errors

def play_round():
sentence = choose_sentence()
clear_screen()
print("Type the following sentence as fast as you can:")
print()
print(f"📝: {sentence}")
print()
input("Press Enter when ready...")

clear_screen()
print(f"📝: {sentence}")
print()
start = time.time()
typed = input("Your input: ")
end = time.time()

wpm, accuracy, errors = calculate_wpm(start, end, sentence, typed)

print("\nResults:")
print(f" Time: {round(end - start, 2)} seconds")
print(f"📈 WPM: {wpm}")
print(f"🎯 Accuracy: {accuracy}%")
print(f"❌ Errors: {errors}")

def main_menu():
while True:
clear_screen()
print("=== Type Racer Main Menu ===")
print("1. Play")
print("2. About")
print("3. Exit")
choice = input("Choose an option: ")

if choice == "1":
welcome()
countdown()
play_round()
input("\nPress Enter to return to the menu...")
elif choice == "2":
clear_screen()
print("Type Racer")
print("Version: 1.0")
print("Made with ❤️ in Python")
print("\nRace against yourself to improve typing speed and accuracy!")
input("\nPress Enter to return to the menu...")
elif choice == "3":
clear_screen()
print("Goodbye 👋")
time.sleep(1)
break
else:
input("Invalid option. Press Enter to try again...")

if __name__ == "__main__":
main_menu()

You might also like