Simple Robot Algorithm

Picture of Robot

Today I had some fun creating a very simple robot algorithm. An algorithm is basically a set of instructions that you follow in a certain order to complete a task. For example, that delicious apple pie recipe you like to use. The way you follow it is an algorithm. Every time you put on your shoes and tie them, that's an algorithm. When you're in the shower washing your hair, that's another algorithm. The same goes for brushing your teeth to making your favorite cup of tea.

To learn a little bit more about algorithms you can visit this page here: What is a Computer Algorithm

I decided that if I ever created a robot and I'm turning it on for the first time I wanted it to greet me and save any information I gave it to variables that it can store for present and future use.

I wanted the robot to save my name and also the day I was born so that when my birthday comes around it will send me a Happy Birthday greeting. That's another algorithm that I'll have to do for another future project. Maybe for that future project I can also create an algorithm where the robot not only greets you on your birthday but also reminds you of other important things like other people's birthdays, anniversaries, and even appointments.

Picture of Robot

I then wanted my "very futuristic robot" to be programmed to help humans with three particular chores. I needed to make sure that when a human inputs an answer pertaining to the chores that the answer would be something that I can control. For example, what if the robot were to ask the human "Do you need my help?" and the human replies with an "n" instead of a "no?" What if the human replies with a "NO" or a "No?" and or replies in the same way with a "yes?"

If you don't anticipate the human's response to all possible human answers then the algorithm might not work exactly as you intended it to. That's why I provided a few "fail-safes" in case this happened. That way if the human replies with all the variations of "yes" and all the variations of "no" it will work. If the human mispells the word "yes" or "no" or gives a different answer that is not any of those "yes or no" variations another fail-safe happens. The human will be prompted three times to enter a "yes" or "no". If it does not comply after the 3rd time the human will receive a "very interesting message" from the robot.

Of course for now this is a speech chatbot where the robot and the human are communicating through the written word. Later on I'm sure I can implement a speech and voice recognition option. But for now this will do perfectly.

I also learned about the "break" and "continue" statements in Python. The break statement came very useful when I created a "while loop" in my robot algorithm which you can interact with to get the "very interesting message" from your robot overlord...I mean robot.

If I didn't use a break statement the robot algorithm would keep asking the human over and over if they need any help. If the human finally answers in one of the many variations of "yes" or "no" then the algorithm ends. What the continue statement does is when the program reaches a continue statement the program immediately jumps back to the start of the loop. So unlike the break statement, continue jumps right back to the top of the loop rather than stopping it like with the break statement.

Ready to see this simple robot algorithm in action? First up is the Greeting Robot Algorithm. Go ahead and interact with it! Click on the Play Triangle to make it run.

And this one is the Robot Chore Algorithm. If you want to stop the program so you can see what would happen if you decide to disobey your robot just click on the square stop button and then press the Play Triangle again. When you do this type any word or letter that does not have a "yes" or "no" variation to it.

Not bad for a very simple robot algorithm huh? Since I created a very simple robot algorithm using what I have learned so far in Python you know what that means right? It's time for the Woohoo Dance!

Picture of Robots Dancing