Teach Me Python #5: Simple Maths

by BlueBlood Studios in Circuits > Software

720 Views, 5 Favorites, 0 Comments

Teach Me Python #5: Simple Maths

2014 17:09.jpg
Today we will be learning how to preform simple maths operations in python such as adding, subtracting, multiplying and dividing. If you have any python related questions of want to suggest something for the python tutorial series please comment and as always favourite and subscribe.

The Code

2014 17:09.jpg
We will begin by coding a simple calculator so open up a blank python file and type the following code:

number1 = input("Enter the first number: )
number2 = input("Enter the second number: )
numberAdd = number1 + number2
numberMinus = number1 - number2
numberMultiply = number1 * number2
numberDivide = number1 / number2
print(number1, ' + ', number2, ' = ', numberAdd)
print(number1, ' - ', number2, ' = ', numberMinus)
print(number1, ' * ', number2, ' = ', numberMultiply)
print(number1, ' / ', number2, ' = ', numberDivide)

The symbols for each operation are:
multiply = *
divide = /
minus = -
plus = +
divide (logical) = // --does not use decimals, rounds it if it is
modulus = % //divides and calculates the remainder
And that is basic python maths