Precedence and Associativity of Arithmetic Operators

preview_player
Показать описание
Python Programming: Precedence and Associativity of Arithmetic Operators
Topics discussed:
1. Precedence of Arithmetic Operators.
2. Associativity of Arithmetic Operators.

Music:
Axol x Alex Skrindo - You [NCS Release]

#PythonByNeso #PythonProgramming #OperatorsInPython
Рекомендации по теме
Комментарии
Автор

Expression: 15 + 3 / 4 * 10 ** 2 ** 2

Exponents (right to left): 2 ** 2 = 4
Expression now becomes: 15 + 3 / 4 * 10 ** 4

Exponents (right to left): 10 ** 4 = 10000
Expression now becomes: 15 + 3 / 4 * 10000

Multiplication and Division (left to right): 3 / 4 = 0.75
Expression now becomes: 15 + 0.75 * 10000

Multiplication and Division (left to right): 0.75 * 10000 = 7500
Expression now becomes: 15 + 7500

Addition: 15 + 7500 = 7515.0

This is a right answer because the associativity tells the direction of execution . Means if *, /, //, % are present in expression then solve what operator is present on left do not solve * first and / second like that .
when I was solve this expression on my book I get the answer 15.00075 because I done * first then / . and when I put this expression in command prompt then I will get 7515.0 then I ask chatgpt and I came to this final conclusion that associativity tells the direction of execution . like left to right etc.

JayendraNaik-lc
Автор

>> 15+3/4*10**2**2
>> 15+3/4*10**4
>> 15+3/4*10000
>> 15+0.75*10000
>> 15+7500.0
output = 7515.0

mdazimuddin
Автор

1. ** - right to left
2. Rest operators - left to right ( including bodmas one)

unnatisrivastava
Автор

15 + 3 / 4 * 10 ** 2 ** 2
15 + 3 / 4 * 10 ** 4
15 + 3 / 4 * 10000
15 + 0.75 * 10000
15 + 7500.0
7515.0

rathinsinha
Автор

15+3/4*10**2**2 ---this is equations
first is power associtivity from right to left
1. 2**2=4
Then 15+3/4*10**4
2. 10**4=10, 000
Then 15+3/4*40, 000
3.mutiplications have high associativity because it is left to right *, /, //,%

So, here multiplication first:

4*40, 000=1, 60, 000

Then eq is :
15+3/1, 60, 000

3/1, 60, 000=0.0001875

Then eq is 15+0.00001875 =15.00001875

15.00001875

Pardhu-gg
Автор

Ans:
7515

(Why did some of you write 7515.0?)

PaintingsbyT
Автор

7515 is the correct answer for this question how many members will accept this answer is correct please click on like button

ErothiJaya