My code is very slow, what's making it like this and how can I fix it?

Question:
My code is unbearably slow, I want to speed it up to be fast and smooth. What’s making my code slow and how can I fix it?

import threading, replit, time, random
from getkey import getkey, keys

print('\033[?25l', end="")

keys = ["-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"]
score = 0
speed = 0.1

def keypress():
        global score, speed
        while True:
                key = getkey()
                if key == keys[0]:
                        score += 1
                        speed / 1.25
                else:
                        speed * 1.25
                        score -= 1

t1 = threading.Thread(target=keypress)

t1.start()

while True:
        print(score)
        for i in keys:
                print(i, end="", flush=True)
        time.sleep(speed)
        keys.pop(0)
        keys.append(random.choice(["-", "w"]))
        replit.clear()

t1.join()
2 Likes

you can’t really fix this… sadly because it’s due to replit. You just need to move from replit

I just wonder why you use threading. This can be done with plain non threaded and faster code i think.