← Back to all posts
##### Why isn't this working

So I made this code but I don't understand why it isn't working. There aren't any errors too sooooo... Can someone help me out.

hotnewtop
InvisibleOne (3206)

Here's my code, this should help:

``````from getch import getch
import time
import random
import os
from colorama import Fore, Style, Back
# You can change these to whatever sentences you want
level1 = ['haha this is a cool typing game using getch. ', 'i am a good typer and my score will prove it. ', 'coding is fun and i love to do it. ']
level2 = ['Wow!, this is cool. I like this game! ', 'Python is awesome! It is easy to use as well as fun. ', 'Typing is fun! And it gives my fingers a good exercise! ']
level3 = ['Is 2 + 2 Four? Or is it equal to 8?', '1234! Counting is fun. 5678 Yay!', 'The first number is 1! The second number is 2! And the third number is 3!']
def split(x):
return [char for char in x]
def get_list(x, count):
try:
value = ''
for i in x:
i = Style.BRIGHT + Fore.WHITE + i + Style.RESET_ALL # this sets the color of the text you need to type
v = x[count]
x[count] = Style.BRIGHT + Fore.BLACK + Back.GREEN + v + Style.RESET_ALL # this sets the color of the current letter that is needed
for i in x:
value += i
return value
except:
playing = True
while playing == True:
time.sleep(1)
start = time.time()
sentence = random.choice(level1) + random.choice(level2) + random.choice(level3)
win = False
out = ''
os.system('clear')
count = 0
while win != True:
ls = split(sentence)
length = len(ls)
os.system('clear')
copy = ls
out_s = get_list(split(sentence), count)
print(Fore.CYAN + Style.BRIGHT + 'Type this sentence: ' + Fore.WHITE + Back.BLACK + out_s)
print(Style.RESET_ALL + Fore.CYAN+"                >>> " + Style.RESET_ALL + Fore.GREEN+out)
key = False
while key != True:
try:
key_needed = ls[count]
print("Key needed is: " + key_needed)
try:
get_key = getch()
if get_key == key_needed:
out += get_key
count += 1
key = True
else:
print(Fore.RED + 'Wrong key! You pressed ' + get_key)
except:
print("Error! Try again")
except:
if length == count:
print("Great job! You won!")
win = True
playing = False
key = True
# here is how the score is calculated
end = time.time()
time_taken = end - start
score = int(100 - time_taken)
print(Fore.GREEN+" SCORE: " + str(score))
else:
print("Error!")``````
MikeJMS8910 (234)

@InvisibleOne wow that is so cool, is it ok if I post it but I will re write it and give you credit