Python tutorials #1 – basic calculator

This is the first of my Python tutorials! Python is a programming language but unlike C++ and Java, is easier to learn but can still be used to create amazing programs such as web browsers, calculators, word processors, and more. But unlike Scratch, a GUI used to make games and other projects aimed at beginners and young children, you still must master Python to create amazing applications using it.

So, here’s my first tutorial: a basic calculator that can be used to add, subtract, multiply, and divide two numbers. Unlike the calculator app preloaded on your PC or phone however, it is CLI based so you won’t have a friendly GUI calculator but rather one where you type two numbers, what you want to do with them, then get the result printed to the screen.

This guide assumes that you are using the newer Python 3.x. The code may work on Python 2.x, but has not been tested, so if you need to stick to Python 2.x for some reason, you may have to make adaptations to the code for it to work properly.

Fire up your Python IDE (such as IDLE3 or Geany) and enter in the following code:


first_number = input("Enter in first number: ")
second_number = input("Enter in second number: ")
print(int(first_number) + int(second_number))

This basic block of code will ask you to enter in the first number, then store that first number, then enter the second number, store that second number, and then show the answer. The int around the variables converts them into intergers so they can be added together as numbers, not as characters. Without this 5 + 10 would equal 510, not 15.

This, however, is a little restricted. You can only add the two numbers, not subtract, multiply, or divide. Asking the user for what they want to do with the two numbers and then doing that expands the calculator’s functionality. For example:


first_number = input("Enter in first number: ")
second_number = input("Enter in second number: ")
option_choice = input("Add, subtract, multiply, or divide? ")
if 'dd' in option_choice:
print(int(first_number) + int(second_number))
elif 'ubtract' in option_choice:
print(int(first_number) - int(second_number))
elif 'ultiply' in option_choice:
print(int(first_number) * int(second_number))
elif 'ivide' in option_choice:
print(int(first_number) / int(second_number))

We are not doing if statements to see if, for example, option_choice equals ‘add’ as Python is case sensitive in this area. Checking for ‘dd’ (end of ‘add’) ensures that the program will work regardless of whether A is capital or not.

So there you have it! A basic calculator made in Python. Currently lacks support for decimals however, so if you try entering decimals the program will error out. This guide is aimed at beginners, so this calculator will likely be expanded on in a future guide. Enjoy!

-Chas 😎

Minecraft for Parents – #5

Sorry for not posting any guides for a few days.

Today I will explain Survival mode, a mode where your possibilities are limited by the fact that you have to collect items before using them.

To use Survival Mode, follow this guide to create a new world if you can’t remember how but change the gamemode to Survival instead of Creative. As a beginner, you shouldn’t try Hardcore as this gamemode doesn’t allow you to respawn after being killed once.

In More World Options, make sure cheats are disabled and enable Bonus Chest as this is a great feature for beginners. Then ignore the seed box and click Create New.

Version Difference:

The other versions of Minecraft don’t allow Bonus Chest which is a shame. Just ensure cheats are off and change Gamemode to Survival and click Create!

Look around for the bonus chest. Open it and you should get some starter items:

I got a stone pickaxe but as these chests are randomly generated you probably have different things.

Click on the item to move it. Hover over your inventory and click a free slot in your hotbar.

Then press ESC to exit the chest. Remember to do the same with all the other things (drag them to your inventory or hotbar).

Or, to suck all items into your inventory, close the chest with all the items in, and then mine the chest or the torches.

Some Minecraft Experts may say that you should not mine the chest and torches because if you need to find your starting point for some reason then the chests will show you it. However, torches are helpful for lighting up dark areas and when your inventory becomes full as you get better you may want to store your items in a chest.

Move around just like normal Minecraft and the next guide will come soon!