Teach Me Python #5: Simple Maths

About: This project has expired.

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

    • Indoor Lighting Contest

      Indoor Lighting Contest
    • Make It Fly Challenge

      Make It Fly Challenge
    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest

    Discussions

    0
    None
    Legend Mark

    12 months ago on Step 1

    very nice am happy an will like to know more