Academy Home | Student Dashboard

CS105 intro to Python unit 2, practice with operator precedence

Hello I wonder if someone can help me understand how python comes up with the answer 6 to this script


what is going on here, the way I see it, v**v is exponent and done first so that’s four.
then I am not sure what to do, if you do x%x which is the remainder of 4/4 that is zero. so I end up with four // 0 which is not possible

1 Like

The way i see it what if we have Y which is = 2 and W = 3, Then we can say (y= 2×W=3)=6

I also did assessment Unit 3, when I review my answers and author’s, they are the same, meaning I got it right. Then am being marked zero…what’s happening??

1 Like

There was this example I saw in Unit 3. I was getting syntax error when I tried to do same as was in the slide. Is there something that is there which I’m not supposed to do oris there a mistake? .

I played around with this a bit, adding parentheses to verify the sequence of operation::


Left to right with the only meaningful deviation being the second grouping taking place before the +, in accordance with arithmetic operator precedence.