Practice Math – the Python Edition

One of my projects this Summer is to create a working version of my Practice Math project. The goal of this project is to create a site that my kids can use to practice their math.

The idea was to create a simple site that would randomly generate math equations that kids could use to practice addition, subtraction, multiplication, and division. To do this, the site would need to have the following functions, at least in the first phase of my project:

  1. Randomly generate two numbers, and a math operator to create an equation;
  2. Evaluate the solution to the equation;
  3. Prompt the child to offer an answer to the equation;
  4. Compare the child’s answer with the actual solution, and give feedback;
  5. Make sure that equations don’t produce negative solutions (our kids haven’t really learned how to work with numbers less than zero); and
  6. Round answers to two decimal places (it can be more than this, I just picked two decimal places for now).

Version 1 – the Javascript Edition

My initial version of the project was based on Javascript. You can find that one here, on GitHub. I wasn’t able to make much progress beyond randomly generating the numbers and math operators that would be used in equations.

I hadn’t worked out how to evaluate the randomly generated numbers, more move much beyond point two in my list of features. I’m certain it’s possible, I just hadn’t worked it out yet.

Version 2 – the Python Edition

I recently decided to return to learning Python. I last attempted to learn Python about a year and a half ago. At the time, I was learning Python 2.7.x. I didn’t move beyond loops at the time.

This time, I decided to start with Python 3.x, which is the current version. I’ve been learning when I have time, and I really like the language. I decided to revisit my Practice Math project and create a Python version to help me learn the language.

I finally sat down this morning, and worked on a script that does all six of the things I want it to do. I’ve published my code on GitHub, here. Here it is in action:

I can’t take credit for what you see there, not entirely. I borrowed pretty heavily from a few sources to produce the version you see there:

Cory Kramer’s solution (the third one in this list) was particularly helpful because it helped me split my code into disparate functions. This makes the script a lot easier to read, and tweak.

My current code still has some test stuff in it. For example, the script current prints the two generated numbers, the operator, and the solution so I can check that it’s all working properly:


print("\nThis is for troubleshooting purposes only:")
print(num1) # For testing
print(num2) # For testing
print(op) # For testing
print("\nWhat is {} {} {}? > ".format(num1, op, num2))
solution = round(eval(f"{num1} {op} {num2}"), 2)
print(solution) # For testing

Next steps

The next step is to create a web interface for this. A command line version is fine to play around with, but for this to be useful, it needs to be a web site. I haven’t worked out how to add a Javascript front-end to this (I believe it’s possible, I have no idea how to do it, though).

What I’ll rather do, though, is use a Python web framework like Django to create a front end for the site. I’m really keen to learn how to do that, partly because I want to port my Modiin Bus project over to Python too at some point (I discovered that the transit data that I’d like to use is available through Python APIs).

At the same time, I also intend figuring out how to represent fractions in the web interface. I know that’s it’s possible to use Javascript to represent fractions on a web page using options such as math.js and MathJax. I’ll look for equivalent options for Python/Django.

There are also a couple niggling issues about the current version that I’d like to resolve too. These likely exist because I’m still very much a Python newbie.

I’m sure there are other improvements I could make to how the script accepts, and processes input from users. I’ll figure that stuff out as I go. For now, I’m pretty please that this core script seems to be working.

Critical steps to get things done when you clearly lack focus

How to get things done

We live in a wondrous technological age that also makes it harder to get things done. This is a challenge when you have a lot of things to do. Obviously.

Fortunately there are a few steps you can take to be more productive. Here is my list for tomorrow morning.

Step 1: Silence reminders

I love that I can set, snooze and gaze fondly at reminders on my phone. I also really like how Google Calendar can help me schedule time to achieve goals such as learning Hebrew, how to code in Python and do my weekly reviews.

It’s all great.

The problem is that these reminders tend to chime at the same time when I am in the middle of some or other task. That is mostly my fault because I don’t really think through the timing for my reminders when I set them.

My first step is going to be clearer about when I need to block off time to finish a task. With that done (possibly by blocking off the time in my calendar), I can set my reminders for “unreserved” times.

Step 2: Email should know its place

I know better than to keep checking email throughout my morning whenever my phone informs me that I have received more email. Sadly, I have forgotten the importance of batching this sort of stuff.

Email, calendar defrags and task batches (or "How Gina Trapani could preserve my sanity")

My next step is to remind myself to keep my email tabs closed until I reach my designated time slots dedicated to checking my email and other batch-able tasks.

Step 3: Be antisocial

I should have paid attention to Catherine Jenkin’s Facebook/Twitter hiatus. She clearly had the right idea.

https://twitter.com/cathjenkin/status/852071262914531328

Although I am tempted to take an extended break from social media, I probably won’t. What I can, and must, do is severely limit how much time I spend on social when I need to focus on my work.

I am also going to keep WhatsApp and Skype closed. Yes, people contact me through those apps and some of those conversations are even work-related. But do I need to keep the apps open all the time and check them obsessively? Probably not.

I can batch this stuff too.

So, step 3 is resisting the idiotic urge to open Facebook/Twitter/Google+ (yes, it is an equal opportunity, time-wasting urge) when I should be focused on the task at hand. That goes for WhatsApp and Skype too.

https://twitter.com/cathjenkin/status/856187110784675840

Step 4: Quiet, you beast!

One of the biggest culprits is my phone. It notifies me about everything. My phone finds everything just so exciting that it has to tell me immediately.

Lacking discipline and willpower, I pull my attention away from what I am working on and check my screen far too often. Each time I do that, I break whatever flow I’ve managed to cultivate and cost me additional time restoring my focus on what I was doing in the first place.

This sort of thing does not constitute “winning” when you need to get things done.

Fortunately, my phone has a handy “Do Not Disturb” mode that silences notifications from anyone outside my family members. It also silences incoming phone calls, which can be a challenge in itself, but the benefits may outweigh the downsides.

Step 4 is going to be to switch my phone to “Do Not Disturb” and cut out most of those little interruptions that pour in throughout the day.

Note to self (2017-04-26): Create an exception for event notifications so you don’t inadvertently miss the important, scheduled events you need to attend!

https://twitter.com/cathjenkin/status/856187258839457792

Right, so that is the plan for tomorrow and, quite possibly, all the other work days that follow.

I hear that it can be pretty rewarding when you actually get things done when you mean to.

Featured image credit: Veri Ivanova

Loving OmniPlan

I’ve been trying OmniPlan out for the last few days as some of my projects are becoming more and more complex. It’s quite a bit of a learning curve but I’m enjoying this app!