Introduction: Simple Remainder Calculator in Python 3

About: Hi! I'm RedKing9132! I am 13 years old. I am into gaming, coding, 3D design, 3D pictures and 3D animation. Visit my blog: redking9132.wordpress.com

Hello everyone,

I am back with another Instructable, this time about coding (or programming). I have been learning an awesome new coding program, Python 3. It is a really popular language and is used by Microsoft, Google, Disney and NASA (apparently). I have only been using books and the Internet to teach myself. I have been experimenting with Python and it has been really fun.
In this Instructable I will be teaching you how to make a simple program in Python that will calculate the remainder and answer when you divide two numbers. Okay, that sounded really dodgy... what I'm saying is that you enter two numbers (like 4 divided by 3) and it would come up with something like '1 remainder 1'.
Let's get straight into this Intructable now.

Step 1: Installing Python

Python is completely free for Mac, Windows and Android.
To install Python, go to this website: https://www.python.org/downloads/ and download the version of Python that starts with a 3, because that is the version I will be using here.
I am using an Android tablet. For Android, jump on the Google Play store and search 'QPython3'. It should be the first result.
I am sorry iOS users, you will have to buy Python for iOS.
Please look at the pictures to make sure you have the right version.

Step 2: Create a New File

I'm sorry, I can't explain this very well. What you need to do is make a new file (also called a script) and name it something like 'Remainder Calculator.py'. You can do this easily on Android by using a file manager app like ES File Explorer or ASTRO File Manager. On QPython3 you can alternatively press on 'Editor' and then press the icon that looks like a page with a '+' in the middle. NB: You can name the file whatever you like, but it always has to end with the extension .py.

Step 3: Open the File

Open the file so you are able to edit it. I would recommend you use a 3rd-party app to edit it, because it will probably colour code your code and automatically insert indents (we'll talk about these soon). If you don't, open the file as a text file. If I haven't explained what you specifically need to do, I'm sorry, you will have to work it out yourself. If you are using QPython3, look for the file under 'Programs' and open it.

Step 4: Let's Start Coding

First, type in:
def remaindercalculator():

This is a function. It tells Python to do things inside it when the function is called.
Press enter when you have finished typing.

Step 5: What Does the Function Do?

Now for some trickier code:
number1 = int(input("Enter the first number: "))
number2 = int(input(number1 + " divided by: "))

Make sure you have exactly 4 spaces before each of these lines. This tells Python that they are inside the function. Note the other spaces in the text? Make sure you include them.
Press enter when you have finished typing.

Step 6: Calculating the Answer

Type this in (remember to put 4 spaces at the start of each line if you need):
answer1 = number1 // number2
answer2 = number1 % number2

The first line divides the two numbers.
The second line calculates the remainder of the two numbers.
Press enter when you have finished typing.

Step 7: Displaying the Answer

Nearly there! Type this in:
print(str(answer1) + " remainder " + str(answer2))

This code will tell Python to display the answer when you use it. e.g. '56 remainder 8'
Press enter when you have finished typing.

Step 8: Handling Errors

This step is optional. This will probably prevent errors happening if the user types in a letter instead of a number.

try:
remaindercalculator()
except:
print("There was an error.")
remaindercalculator()

The second, fourth and fifth line have 4 spaces at the start. The first and third line have none.

Step 9: }{}{ If You Skipped the Last Step }{}{

If you skipped the last step, do this step. It's as easy as 1, 2... whatever comes next. Type:
remaindercalculator()

There are no spaces before this line.

Step 10: Conclusion

You are finished! Now all you have to do is save the file and run it on Python!
When it asks you, type in a number and press enter. If you type in a symbol or letter (and did not use the error handling step), the output will be 'There was an error.'
This Instructable took a while to construct, so please leave a favourite, comment and maybe even follow me...! If your code does not work (i.e. has bugs in it :] ), please leave the error message in the comments or email me at redking9132@gmail.com and I will try my best to fix it!
More Python tutorials coming out soon...

RedKing9132 out!