0

Using the mathematical operations which operation we have to use first.

according to mathematics first we have to perform the division, then multiplication, then addition then subtraction, but in this lesson I was instructed that I have to perform the operation first which are in the parentheses. what to do

8th Nov 2016, 7:35 AM
chiranjibee padhee
chiranjibee padhee - avatar
3 odpowiedzi
+ 1
Hello, acording to my knowleage of math, you should first perform operations in all parentheses in usual order {[( / * - + )]} and then all other operations in same order. Parentheses are used to break the usual order of operations because sometimes you need more compex calcation
8th Nov 2016, 7:46 AM
Ondra Musil
Ondra Musil - avatar
+ 1
parentheses override normal order. >>> 3*5+7 22 >>> 3*(5+7) 36
8th Nov 2016, 8:40 AM
Kirk Schafer
Kirk Schafer - avatar
0
In Python there is some form of operator precedence. They are listed [url]https://docs.python.org/3/reference/expressions.html#operator-precedence[/url] for python 3. As you can see. addition and subtraction are equal. So are multiplication, division and remainder although they do precede add and sub. Because Python has a lot of operators. Many people use parenthesis. They make it explicit which calculations should be done first. This i.m.o greatly improves readability.
8th Nov 2016, 8:12 AM
Oclee net Evah
Oclee net Evah - avatar