Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

My question looks like this:

10-7//2*3+1

I am supposed to solve the equation.

And my answer seems to come out as 8 when using PEMDAS

First its's 2*3 = 6; 10-7//6+1 

second = 7//6= 1; 10-1+1 

Third = 10-8 = 8;

But when putting it into python, I get a 2. Why?

It seems the order of the program is as such:

first: 7//2=3; 10-3*3+1 

second: 3*3=9; 10-9+1 

third:10-9+1= 2; 2

I don't get it

1 Answer

0 votes
by (106k points)

You can refer the following to get the better order for operations which is PEMDAS is better expressed as

P Parentheses, then 

E Exponents, then 

MD Multiplication and division left to right, then 

AS Addition and subtraction, left to right

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
3 answers
asked Mar 22, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...