Good night all programmers?
As my writing before about Learning if, for, and while function on Python Programming Language, I will continue my next writing on Python learning. We are going to study some mathematics formulas that we can make on Python programming language. As like we know, base formulas of Mathematics are multiplication, division, summation and subtraction. The sequence of the base formulas is as same with the mathematics formulas priority of themselves. It means that the highest priority is multiplication, followed by division, then summation, and the last is subtraction. For example :
2 + 8 x 3 = 26 (correct)
2 + 8 x 3 = 30 (incorrect)
Do you know the reasons why the correct result of the calculation above is 26 ? why not 30 ?As I have described recently that priority influence the result. The example above, there are two calcualting operations, they are summation and multiplication. If we look the priority, multiplication is higher than summation. So, the first executed of the calculation is multiplication, the next is summation. It is different when the summation of numbers in brackets. For example :
(2 + 8) x 3 = 30 (correct)
The result of the calculating operation is correct because bracket is more prioritied than others. And then, how the mathematics formulas are written on Python ? Actually, the rules of calculating operation on Python is almost same with mathematics formulas as generally. I will give you an example below. Don’t forget to open the IDLE of Python, just write scripts on Interactive Mode :
The example above is all of mathematics formulas with integer numbers (type integer). If you calculate decimal numbers (type float), the result is also decimal numbers.You can see the example below on Interactive Mode :
OK friends, I think it is easy to be understood. So, we will continue our learning. The next topic of my writing today is degree, root, and remainder of division.We need to see this example immediately :
Explanation :
- Degree formula on Pyhton is x**y where x is number that will be powered and y is the power.
The scripts above show that we have to import modul first to be able use root function. On Python, named modul had provided in lib directory. You can see some moduls that had provided in :data C/Python 2.7/lib/
I will describe the script of “from math import sqrt as root” it means that we import sqrt function/formula from math modul where sqrt function itself is root function. Then, the sqrt function is represented by root (the name is up to you friends, it means you can change the name for example bob or others).
- Remainder of division (%). On the example above, we look var a = 17, then var b = 17 % 3 it means 17 is divided by 3 get 5 with remainder 2. From mathematics operation, the result is taken from the remainder of the division.
That is base mathematics formulas that we learn today. By understanding this base formulas, we could make triangle formula, square formula, cube formula, circle formula, and so on.On my next writing, I am going to share about some advanced mathematics formulas as like I mention above. The point, just truly understand this base formulas so that you can learn more advanced formulas easier, OK please study hard my friends. ;)