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.
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.
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.
Continue reading “Search Quest VII: The Search for Search (A Python Story)”
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.
Continue reading “A Short Python Script About The Distance Between Two Points”