Maths and Numbers

Every programming language have math and number functions. So does Python and its very easy to use these functions.

+ plus
- minus
/ slash
* asterisk
% percent
< less-than
> greater-than
<= less-than-equal
>= greater-than-equal

Now lets see some examples to understand better about these codes. To learn it easily we will use python console.

Python Console

Python Console is built-in tools of python to check syntax and do error check. To launch this tool just run python using cmd/terminal, in my cause I am using MAC so I have to run python3.5 (I need to specify python version as I have multiple python versions installed), in case of *nix you also need to specify python version as *nix have python2 already installed. In case of windows, you just need to run python from cmd. To exit from console use exit().

Python Console

As you see in console we can use numbers in python very easy. Let's see that using a exercise.

Exercise1:

In this exercise, we will do some simple maths and print them.

Code:

Python3 Maths and Numbers Exercise 1I belive you can understand this code very easly.

Output

Maths and Numbers Output1

Now that we understand how python manage maths and numbers its time to do it with variables.

Exercise 2:

This time we will use variables and do some simple maths.

Python3 Maths and Numbers Exercise 2

In line 13, we have redefined our old variable and used it again with new values.

Output

 

About the author

akarperiwal

0 Comments

Please login to comment