

I can do that manually: def accuracy(typed_list): The accuracy() function works, but can be simplified. I altered my design:ĬhatGPT had most of the pieces it needed now. The unsolicited addition of printing the typing speed threw me off at first. I moved on to the next function I had in mind: It’s a flaw in ChatGPT’s code, but an easy manual fix: def typing_speed(text, start_time, end_time):

I asked for the gross speed, which considers any sequence of five characters to be a word. None of these alter the word count, but they do impact typing speed. The problem is: this metric ignores the length of words and overlooks symbols such as spaces and punctuation. This calculates raw typing speed by dividing the number of words typed by the time taken. Next, I asked ChatGPT to write a function to calculate the gross typing speed. Pretty good! Just needs some color: Insert comment about f-strings. I use a mac, so I left the code as is and continued: It's also worth noting that ChatGPT's implementation won't work on Windows machines. It would be incorrect, but consistent with the kind of errors I saw before. Based on my previous conversation, I expected a solution using (1) but without using tty.setraw(). I already knew how to tie them together, and was curious to see if ChatGPT could fill in the gaps. I split up the program into several functions. For my second attempt, I took a more active role in solving the problem and gave ChatGPT much more specific instructions. Up until now, I had interacted with ChatGPT as a consumer with no knowledge of programming. But it captured enough of what I asked for that it inspired a new plan of attack: Like I'd found for generating text, ChatGPT struggles to create good code en masse. I let it know how I felt before I closed the chat:

I spent a good half an hour trying to get ChatGPT to fix its code, but things just kept getting weirder and weirder. It looks reasonable, but it doesn't work: I tell ChatGPT that the program doesn't work as expected and reiterate that the colors should be applied to the text as the user types it. That's not quite what I want, but it's getting closer. But it doesn't color the user input as I requested:Īgain, the code runs. It is, for all practical purposes, a functional typing analysis app. It gets the accuracy calculation correct and computes raw speed in words per minute. It's impressive how much ChatGPT gets right here. I've been thinking about building a terminal app to practice typing for a while, so I decided to give ChatGPT a shot at building it.ĬhatGPT's program is surprisingly close to what I want: "well-commented"

This article was originally published in my Curious About Code newsletter.
