0
How do languages calculates??
How does a language (Python or JavaScript) break down mathematical problem like this Assume a=7, b=5 ,c=4 . =>(a+c)-a*b%a
4 ответов
+ 9
Indiphile Menziwa ,
the calculation (in python) is done according the so called * operator precedence*. this can be found here:
https://docs.python.org/3/reference/expressions.html#operator-precedence
so your expression is evaluated and performed like:
a = 7
b = 5
c = 4
* and % have the same precedence, so they are used from left to right.
print((a + c) - (a * b) % a)
( 11 ) - (7 * 5) % 7
( 11 ) - ( 35 ) % 7
( 11 ) - ( 0 ) => 11
so the result is 11.
+ 5
Indiphile Menziwa it is a complicated process that is called "lexical analysis". Geeksforgeeks appears to have one of the better explanations of how it works. https://www.geeksforgeeks.org/introduction-of-lexical-analysis
+ 3
Syntax error +%
Usually the modern programming languages follow the same operator precedence as common math notation
1. parentheses
2. exponentiation
3. multiplication, division
4. addition, subtraction
+ 3
Thanks 🙏, that lexical explain explained more than just calculations. And appreciate the explanation Lothar that's exactly what I was looking for😸