Python in Algebra 2 – An Experiment

One of my goals is to include some Python programming as part of all of my courses this year, and to do so in a way that isn’t just wedging it in where it doesn’t belong. We don’t have a formal programming class in our school given our size, but I have heard that students are interested in the broad topic of programming, and know that they could benefit. So, I am finding times to get students playing around with it as a tool.

The perfect opportunity in Algebra 2 today came in evaluating algebraic expressions. I don’t like reviewing the topic, at least haven’t in the past, because in most cases the students remember enough of it to think that they know how to do it, but have forgotten all the nasty bits about order of operations, distributing negative signs, and the infamous -5^2 = 25 when evaluating -a^2 at a = -5. They typically have great interactions reminding each other of the rules, but by the time they get to me in Algebra 2, the idea is no longer fresh. The lesson then ends up being the math lesson equivalent of an air freshener – temporary and stale.

Following my goal, I figured this would be a perfect opportunity to introduce the topic first as a programming topic, and then use the computer as a resource for the students to check their arithmetic. We started the class with some basic order of operations questions:

This was followed by pasting the following into a Python interpreter as everyone was watching:

print “Answers to the Warm-Up Questions:”
print (8*3 – 2*4)
print (27 + 18/9 – 3**2+1)
print (40 + 24)/8 – (2**3+1)

This was following a suggestion from Kevin Krenz to demonstrate the fast way to solve it using the Python interpreter. While they weren’t wildly impressed, they did accept that this was an option for them to check their work in these types of questions, and were up for learning how it worked.

I then showed them how to run a Python file on their Macbooks, which all have at least Python 2.6 running on them in the terminal. I talked about working in the terminal as running around in the basement of their computer – lots of power and hidden secrets there to play around with (or mess up if not careful). After learning to do this, they edited a partially completed Python script which I have posted at Github here.

I really liked what happened afterwards, though it did not feel (at all) like a clean, straightforward way of going over algebraic expressions. It was messy. Different people were at different places during the entire 30 minutes we worked on it, which was much longer than I expected. Quite appropriately though, it slowly came together like writing a program often does. Lots of good discoveries and realizations of simple errors that I didn’t need to force.

Students realized the difference between 2*x and 2x to the computer. They realized quite cleanly that they needed to tell the computer outright that there is multiplication between a coefficient and a variable. They saw this was not the case for -x although they also thought they might need to write it as -1*x. The Python interpreter pointed this out to them immediately. The interpreter didn’t do so well on 4(3 – x) since it considered it a function call, but with some prodding, most students realized it was the same error.

There was enough information in the script for them to figure out how to do exponents, so I was happy not to have to go through that separately. The only really big problem was the fact that Python 2.6 doesn’t have the nice floating point capability for division that 3.2 has. For the first problem, part (a), the answer is 0.5, but Python returns 0 since it assumes integer division with a plain / symbol. I went around to student computers replacing x/y with x*1./y, but this became an opportunity to converse with students about division as multiplication by the multiplicative inverse or reciprocal. Another unintended complication that then resulted in more review of pure mathematical concepts.

With all of this done, the students were then pretty proficient at trying to do the substitution by hand and checking against the answers from the computer. Most caught the serious mistakes without too much input from me – the computer did that work for me.

After finishing problem 1, the students got a big kick out of how I told them to program Problem 2 at the end of the script. They were directly teaching the computer to answer these questions through code. I think they saw that programming really is how you teach a computer to do what you want it to do, and had at least a minimal sense of pride in being able to do so.

One student said this was pretty cool, and compared it to a video game. Another appeared to want to kill me the entire time. They were all pretty patient with the activity though, and trusted that this would make them better at what they needed to learn for my class – probably the most important part to this not leading to a serious case of Thursday afternoon mutiny.

In the grand scheme of technology implementation, this activity was nothing more than using Python to replace a graphing calculator with substitution capability. This type of knowledge, however, is important for doing more substantial applications of computational thinking. I think it’s important to get students to see what it can do before being interested in creating something as simple as ‘Hello world’. That doesn’t seem to interest the vast majority of students. While I did most of the programming for this task, this is a gateway to the students doing more and seeing more down the line. Now that they know how to do the basics of editing and running a program, we will be more successful in doing more sophisticated things later on.

Experimenting with iBooks Author

I recently took the step of dipping my feet in the Apple pool, much to the surprise of many people that know me and my preferences. There were a few reasons that I decided it would be a good idea, but one of them was the opportunity to experiment on my own time with iBooks Author.

I’ve tossed around the idea of writing a book. A few ideas for topics have been bouncing around, one being one in which the concepts of mathematical thinking are explored through programming. Given that all Mac computers have Python installed automatically, not to mention the ease that it can be installed on other platforms quite easily, Python is a perfect fit.

Now that I’m set up with my Mac, I’ve spent the last couple of days playing with it and getting to know its quirks. It does have quirks. I spent a couple of hours today battling a mystery white box that covered anything that slid into it, and that remained even after saves, restarts, and reboots. Eventually I got rid of it (though I’m not totally sure that I am sure how) and put together an activity I plan to have some independent study students work through this year.

The quiz options are nice ways to make things interactive, but they have all the same downsides of multiple choice questions. If there was a fill-in-the-blank option, I could very easily see putting together my own self-guided lessons along the lines of Udacity. That’s really what I’m looking for. The really powerful thing to have would be an HTML5 Python interpreter, and I haven’t yet looked to see if something exists that would work with the interface.

I found out late in the process that images placed in landscape mode only show up in the portrait orientation if they are set to be ‘inline’ instead of floating or anchored. Backsliding ensued.

On the whole, it’s a nice free publishing platform, including for nice PDF files. I didn’t have much multimedia material to throw in, and my attempts to do so would have been for exercising features, not for enhancing the book as a learning opportunity. As many have noted previously, iBooks author offers quite a bit of horsepower for generating flashy multimedia textbooks, but the extent to which it revolutionizes education isn’t quite there. Opportunities for interfacing with others reading the same content through chat, messages, or something like that would be a step in that direction.

For what it’s worth, feel free to check out the final product below. While the text is written as if it’s a finished book (“More information on this can be found in the Appendix”), it very much isn’t. Just an experiment to fill my hours battling jet lag back in China.

Mathematical Reasoning with Python

The Problem Database Project – Where do I begin?

I am really excited to be part of this incredibly cool idea – excited enough that setting up and playing around with CSS, HTML, and PHP was my afternoon yesterday. The past ten months really have been my most intense in terms of learning programming. Though I’ve found plenty of interesting projects to take up my time outside of teaching, the Global Physics Problem Database, and whatever elements I can contribute to it, is probably the challenge that I’m most buzzed about taking up.

For those unaware of what I’m talking about, check out these posts from John Burk (here and here)on the conversations and ideas that have been tossed around for the past couple of weeks. I find I am routinely generating skills-based questions for my students frequently, and if there was a reliable site, NOT blocked by the GFW, that I could easily use with my students for this purpose, I’d get a lot of use out of it. Furthermore, one of the highlighted goals of the project is to document its making so that others, including those with limited experience in web applications, can learn how it is being built. I consider myself one of those novices – my web experience has been limited to a three week effort in the Udacity course on web applications engineering. Not exactly enough background to design the next ed-tech innovation to receive millions of dollars, but luckily there are many talented people in this group from whom I can learn.

The bulk of my time yesterday was spent installing the PHP framework Laravel on my laptop. Despite Andy Rundquist’s excellent screencast on doing this on Windows, I was booted from my Ubuntu partition at the time, and said to myself “Why not make things difficult and install it on Linux, the structure of which you still haven’t figured out?”

I learned exactly what I wanted to learn – more details about how the Linux filesystem works, where things are located, etc. The tricks I had to make before getting the Laravel default page to work:

  • In addition to placing the Laravel directory in the /var/www directory, I had to play around with the permissions for that directory so that Apache & PHP could manipulate those files. I kept getting a ‘Laravel failed to open stream: Permission denied” error. The solution I found here worked, but may not have been what I should have done. Oh well – it worked, and it’s a local installation, so I’m not so worried about security at this point.
  • I needed to manually install php5-mcrypt because it isn’t included in the regular installation of php5. Mom, did you know that?
  • I did see the Laravel default page pop up at this point – success! I was playing around with suggested code from the documentation but was having trouble getting anything other than this page to load. I spent an hour just on this issue, staring in disbelief at the pages of Laravel documentation and a number of tutorials (like this one)that told me how easy it was to get started, even for a beginner. Then I found a page with the trick: the local host address needed to include index.php in it in order to run any functions I put into /application/routes.php file. Oops.Once I got to this point I was ready to play a bit more. The dog woke me up early, and I have trouble falling back asleep once there’s any light on the horizon, so I picked up where I had left off with Codeacademy’s courses on CSS. I’m capturing the excitement of learning this stuff for the first time, so for those that have known this for a long time, I apologize if what I am about to say is either painfully obvious or painfully understated.

    CSS is the bomb.

    The fact that adding a style sheet is all that it takes to turn this: into this: is pretty incredible.

I’ve also never used PHP before, but as I expected, there’s enough information out on the web to get a basic idea pretty quickly with the programming knowledge I already have. While the whole Laravel framework is written in PHP itself, the thing that I really like about it is how seamlessly it integrates into HTML code. Here is the code I wrote to generate the list of options at the top of the page, as well as include a welcome message:

Why am I tickled pink by this?

The variables I defined at the top of the code are filled in by the PHP code that appears later in the HTML. If the person loading this page is somehow classified as a student by the variable ‘user_type’, then that person will see this:

If the user_type is instead ‘teacher’, the menu changes to look instead like this:

Depending on the user, the content of that menu will change, as can the functionality of each link. I had no idea how easy it was for the page to change what it looks like with a simple addition of PHP code. In the case of the physics problem database, the values of those variables that correspond to the username, the user_type, and the question_text are going to be coming from the database being designed for the project. At the moment, I don’t really know how to get that information into the page through PHP, but I know the reason Laravel was chosen was to help make this process as easy as possible.

Again, for those more experienced, I understand that this might seem obvious.  I’ve always wondered exactly how it was that web servers provided different web pages at the same address depending on whether you’ve logged in, what privileges you have, etc. I remember how cool I thought I was lurking around in web server directories and looking at different HTML files that you normally couldn’t access unless you were logged in, which I wasn’t – this was before this was identified as the ridiculously obvious security flaw that it was. I understood the idea of cookies and caching, but never took any time to understand exactly how it worked.

Now that I’ve seen behind the curtain, I’m pumped.

Enough for now though – off to work on end of the year comments. One week is left, consisting of classes, giving final exams, grading final exams, and wrapping up loose ends before returning to the US for some good times with family and friends. Oh, and PHP.

My PHP file can be found at .

1 3 4 5