Teach Me Python #5: Simple Maths

Published

Introduction: Teach Me Python #5: Simple Maths

About: 1 new python tutorial every day Comment what you want the next one to be Please favourite and subscribe Notice Board: - since instructables has automatically been removing my indentations from this point o...

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

    • Casting Contest

      Casting Contest
    • Make it Move Contest

      Make it Move Contest
    • Woodworking Contest

      Woodworking Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments