DIY: Programming tutorials EP05 - Coded Mavis Beacon typing test in Python.

Greetings to all,

I hope everyone is having a good day. It’s been a really crazy week day for me as most of you know, I’m in my final year and we’ve got a final year project coming up so you can imagine the kind of stress that is on me. But that is just by the way. I’ve missed you guys :). And I’m here to share a Python program I wrote I think you will love this one.

I call it Mavis Beacon. Im sure the name alone would have clued you in on how it would work. Yeah you are right., the code I will be showing you code is going to provide as with a pre programmed phrase, and then instruct as to type it as fast as possible. After which the speed and accuracy at which the phrase was typed would be announced to the user. Sounds cool right?? Let’s get on with it.

Since we would be dealing with time, we start by importing the predefined function time, and also define the text we want the user to try his hands on. This text could be anything for example I used ”DIY is a community I get to showcase my programming skills. You can choose to enter a different text if you want.

After we have defined the text, we can then go ahead to ask the user to prompt the user to type the above words as quickly as possible by using the Print function

After we are done with the first aspect, we can now print the predefined text in a new line using the /n function. And we also need the user at his own command start the task. So yo achieve this we use the input function where we can ask the user to press enter to start the timer

The next part is where we will do some little calculations in Python. We will be defining about three functions, the first is start time which we will be setting to time.time. The second function end time would also be set to the same string. Now for the time taken for the user to accomplish the task we will subtract start time from end time.

The code is almost complete, it now time to calculate the accuracy of the user which can be achieved by diving the correct characters by the length of the predefined text.

This is the last part of the code. This is where we will print the time taken, and also the accuracy of the user. For the time taken, we can use the function print("\nTime taken: {:2f} seconds". format (time_taken)) and the accuracy we can use print Print("Accuracy: {: 2f}g". format (accuracy * 100)).

Now we can run the code;

After hitting the Enter key, I typed in the phrase DIY is a community I get to showcase my programming skills I used 23.3 seconds to accomplish this task. And had an accuracy of a 100%. You can see that the code runs. Thank you and see you on the next on.

H2
H3
H4
3 columns
2 columns
1 column
2 Comments
Ecency