# Play Bad Banana online at trinket.io!

For curious readers who want to try Bad Banana, but who, understandably, would prefer not to have to download the code and run it on their systems, the game can now be safely played online at https://trinket.io/python/6a564db039?toggleCode=true&runOption=run. Toggle to Code View to see how the game works!

Many thanks to the people behind trinket.io, a great tool for beginners to learn about coding and to share simple programs like Bad Banana.

# Bad Banana – A Python Math Game

It’s been awhile since my last entry, but here is my latest creation, so to speak.

Bad Banana is a text-based math game written in Python 3. My original intention was to use the game as a way to teach basic programming concepts, but I’ve put that idea on hold–I feel it right that I get better at coding first before I attempt to instruct others.  The challenge of the game is to mentally multiply two whole numbers as many times as you can before getting three wrong answers. Once that happens, it’s game over and you’re a BAD BANANA🍌 💩 !

Obviously that was funnier in my head :-p.

Watch the video above to see the game run in IDLE. Alternatively, you can view and download the code from my github repository, and run it however you like on your system. I’m going to try to see if I can actually embed the game on WordPress so readers can play it live on this blog.

Enjoy (I hope)!

P.S. I did not display the code here because WordPress made some unasked changes to it when I used the “code” tags. Very bizarre, but it’s available at github, as mentioned above.

# Search Quest VII: The Search for Search (A Python Story)

Wanting a programming problem to work on but reluctant to tackle a big project, I returned to an old college textbook to look for something challenging but within my pay-grade, so to speak:

Implement sequential search and binary search algorithms on your computer. Run timings for each algorithm on arrays of size n = 10i for i ranging from 1 to as large a value as your computer’s memory and compiler will allow. For both algorithms, store the values 0 through n-1 in order in the array, and use a variety of random search values in the range 0 to n -1 on each size n. Graph the resulting times. When is sequential search faster than binary search for a sorted array?

In short, for lists of data values in numerical order of varying size, compare on a graph the speeds of two search algorithms, sequential search and binary search.

For the benefit of readers who are not familiar with the said search methods, I’ll use an analogy I once heard during my time as a student at teachers’ college. Imagine you have to find the contact information of someone called “Daryl Daryl” in a telephone directory. First, you search for the name sequentially, that is, starting at the very first name in the phonebook you scan each name one by one until you land on “Daryl Daryl.” This, of course, is not how we would look up someone in real life, but let’s suspend our disbelief for explanation’s sake.

# ?????????🙈😬🙄😮?????????

One of the things I don’t like about blogging is how long it can take to put together a blog post, even after it has been written, edited and polished. Aside from all the formatting required to make an entry look the way I want (see above), the other big time-suck has been adding mathematical statements (equations, formulas, expressions, etc.) to my blog. While I love MathType for its ease-of-use, using it has meant I’ve had to suffer through 1) writing math statements in the MathType Editor, 2) inserting them into a Pages document, 3) copying the said insertion into Preview, 4) exporting the Preview file as a PNG,  5) uploading the PNG to WordPress, and, finally, 6) inserting the PNG into the appropriate blog post. This is a lot of steps for something as short as, say, the area of circle (again, see above).

As such, I was happy when, several weeks ago, I stumbled onto MathJax, a Javascript engine which renders  LaTeX  “code” into professional-looking math statements. I had, for a long time, known about TeX and LaTeX as way to create math documents, but had always been satisfied with MathType to get done what I needed done. After doing a bit more investigation and discovering that WordPress already supported LaTeX,  I decided to give it a shot by using a LaTeX snippet I found here and expanding it into an entry on the sum and product of quadratic roots below.

***

Given a quadratic equation in general form $ax^2 + bx + c = 0$, the equation’s roots are

$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\newline \newline$

or

$x_1 = {-b + \sqrt{b^2-4ac} \over 2a}\newline \newline x_2 = {-b - \sqrt{b^2-4ac} \over 2a}\newline \newline$

# A Short Python Script About The Distance Between Two Points

For this blog entry I wanted to do something different. During the past few weeks I’ve been working on a program that allows you to enter two points on an XY plane and find the distance between them. The formula to do this is pretty straightforward and can be calculated as follows:

So here is my little program, or a screen shot of it, at least. Christmas comes early this year! Woohoo :-p.

# Donkeys, Logs, Snakes, Oh My!

For the last several years in the United States and the UK, there has been a strong push to teach primary and secondary-school students how to code. Whether this is a good idea or not, I personally have enjoyed learning about programming. One of my current hopes is to do more programming using the Python programming language.

Now, I won’t get too much into coding—my intention for this blog is to focus on math—but I just can’t resist to somehow meld these personal and professional interests. Namely, how can I use my basic Python programming skills to explore math concepts and solve math problems?

As a starter, I thought that I would introduce readers to the Python interpreter. Basically, this is a program that accepts commands written in Python and executes them immediately. If you’re using Mac OS X or some other Linux\Unix operating system, then the chances are very strong you can just open “Terminal” or your favourite shell and type “python” to get the interpreter running. If you’re on Windows or just have no clue what I meant in the last sentence, then I recommend downloading Python and using IDLE, which you can click on to launch like any other app. I’ll be using IDLE to talk about Python in this entry and probably future ones too.

Suppose you are asked to solve the following:

Currently, there are six donkeys on Nick’s farm. The donkey population grows at a rate of 2.5 times per year. When will Nick have 18 donkeys on his farm? Round your answer to the nearest tenth of a year.*

Typically, we would solve the problem by first modelling the situation as an exponential equation and then rewrite the equation in its equivalent logarithmic form: