Doing My Homework
A means of removing some of the tedious copy-pasting from an introductory python course.
Motivation: Unfortunately, to keep financial aid and full time status at UCSC, I had to keep a certain number of units. To do this I decided to take an easy course, that would fit the time slot I had available. This course ended up being quite tedious, so I decided to make it a bit more interesting for myself.
The Problem
The class has both normal programming assignments, and these 'Quiz’ type assignments.
They are extremely tedious, as the intended completion involves writing the code from each question into the idle shell, then copying the answer back to the answer input box.
This can take a lot of time and does not feel that useful.
So I automated it…
well, part of it.
The Solution
I knew I didn’t want to make something that would actually put in the answers for you, and answering the questions as they come up would be impossible anyways, though a best guess approach could have worked.
And while I was interested in getting rid of the copy-pasting aspect of doing the assignments, I think I landed a happy medium of having the questions automatically written to code files, and still needing the code to be checked.
For the solution I employed some local html scraping with BeautifulSoup and some meta programming.
Issues
There are issues however, as the Questions themselves are not standardized, and are input by hand. This gives even similar looking formats some spacing problems.
This ends up as a sneaky advantage, as it forces anybody using the script to actually have to read and understand the code of each question.
Also, when pulling from the html there are some strange characters and encoding issues. Most get handled, but occasionally something gets through, and when using the IDLE file, you’ll need to specify ANSI encoding.
The Code
can be found here.
How to use it
Go ahead and save the assignment web page.
Preferably close to where you downloaded the script.
Now just run it with the html file.
There are some options you can look at with --help.
The Results
Without flags, you’ll get three new files: .py, .ipynb, and .idle.py.
The python file is pretty standard, though there are comments in it to make conversion to a notebook file. In an editor like notepad++ it makes dealing with formatting and hidden/special characters easier.
Next is the IDLE version of the python file. Its still a normal python file, but with a little something extra for a more interactive experience
If you want to open it in the IDLE editor, you’ll need to specify ANSI encoding, a side effect of scrapping a web page.
Next, you’ll note, the code for each question can be seen twice. This is intentional, so when running as an interactive script in the IDLE shell, it also gets printed. The part in the try/except blocks are what will be run, and often needs to be properly formatted. This a good opportunity to actually read the question, and understand the code being presented. I suggest trying to run the file and fixing the errors as they pop up.
Finally, once you’ve solved your errors and run the file, you’'ll be able to code along with it in single line format.
Here you can see, underlined in red, code written as input, and the out put of that code just below it. The code can interact with the code of the assignment, this is a great place to experiment.
Last but not least, we have the jupyter notebook file.
Of the three, its the one I like the most, as it lets you try each question on its own in their own code blocks. This makes debugging and correcting spacing/format issues much easier as well.
Its output rarely differs from IDLE.
Unfortunately, You’ll still need to paste output and answers manually back into the assignment’s web page, but hopefully it made it less painful.
Notes
This does not actually do any homework for you.
All it does is copy down a web page into python files, and imperfectly at that. You’ll still need to read through the questions and edit the code to make it work.
This helps me understand the assignments better, and finish them more efficiently, though I don’t know if it was worth it for me to automate this. I had fun and it might be useful to you, so ‘eh’.
Feedback
If you tried it out, I’d love to hear how it went! if you have suggestions or comments about it, or perhaps this page itself, please let me know!