Teach Me Python #5: Simple Maths

Introduction: Teach Me Python #5: Simple Maths

1 new python tutorial every day Comment what you want the next one to be Please favourite and sub...

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.

Step 1: The Code

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

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest

    Discussions