Apr-21-2019, 09:39 PM
My second day with book, Atom & Powershell. Using the Python calculator...
Why does--
25+30/6
30.0
Whereas--
55/6
9.1666666666
?
Mark
Why does--
25+30/6
30.0
Whereas--
55/6
9.1666666666
?
Mark
*Ultra beginner math question
|
Apr-21-2019, 09:39 PM
My second day with book, Atom & Powershell. Using the Python calculator...
Why does-- 25+30/6 30.0 Whereas-- 55/6 9.1666666666 ? Mark
Apr-21-2019, 10:12 PM
(This post was last modified: Apr-21-2019, 10:12 PM by Gribouillis.)
Due to operator precedence,
25 + 30/6 is the same as 25 + (30/6) which is not (25 + 30)/6 . It means that the / operator binds terms more tightly than the + operator. In the documentation, there is a table of operator precedence in increasing priority. You see that / is below + in the table, which means that it binds more tightly.In case of doubts, you can always add parentheses in the expression to remove apparent ambiguity.
Apr-21-2019, 11:24 PM
And I had just read 'PE(M&D)(A&S) this morning. But when discerning the current problem my mind 'absolutely' knew, no questions asked, that I would 'of course' add the two numbers then divide. Big lesson--
Thanks, Mark |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Beginner Python Question: FIzz Buzz using while loop | camoyn13 | 2 | 1,873 |
Sep-20-2022, 09:00 AM Last Post: deanhystad |
|
beginner math | MarioM | 13 | 4,754 |
Dec-02-2020, 12:10 PM Last Post: MarioM |
|
Beginner Python Homework Question (Calculate Gross Pay) | matchamochi7 | 4 | 5,766 |
Nov-02-2018, 01:06 PM Last Post: buran |
|
Beginner's String Operation question | docboy | 6 | 3,589 |
Sep-30-2018, 05:49 PM Last Post: j.crater |