One day, I was doing my reading homework, and instead of being like a normal person, I decided to make a Python script to do it for me. So, let’s take it back a few steps and talk about how I actually did it. First, let’s talk about my reading homework site. To prove that I had read the book, I needed to provide the last three words on the page I started reading on, the last three words of the page I finished reading on, and I also had to make a question about the text I had just read and provide an answer to that question. What I did was found a PDF of Harry Potter and the Philosopher’s Stone, then used Python to read this PDF and print the last 3 words of any specified page. Annoyingly, because this was a PDF of the entire book, that included the front cover as an image and some other stuff. This meant that page one for the script would be the front cover, which was just an image and did not have the ‘last three words on this page’ that the script was looking for. So, if someone put in the number one, it would just start spewing errors, which no one likes. To overcome this, I made the script add 1 to the input to make it read page two of the PDF but page one of the story (confusing, I know). So, it would look something like this…
#python 3.9.6 according to sys
targetNumber = int(input('What page do you want the last 3 words of?:'))
targetNumber += 1
Now here comes the second issue again because this is a direct copy of the book. It has the page number (of the story, not the PDF) at the bottom. So if I used my script on page 8, for example, it would print ‘it until 8’ instead of ‘believe it until’. To counter this, I made it get the last 4 words on a page minus the very last one. So that’s part one complete. Now onto part two, ‘creating a question and an answer about the text you have just read’. So, to do this, I made the script also send all the text between the start page and the end page to chatGPT under the prompt ‘make a short question and answer about this text [insert text]’. and so in conclusion it all worked really well but because I don’t pay for chatGPT it only worked roughly 5 times and then it started saying ‘you have run out of credits’. So it was fun to make and fun whilst it lasted and I would definitely do it again.
P.S. I never used this for reading homework because it was too powerful.

Leave a comment