[Python] Understanding the precedence of the modulo operator [duplicate]

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    I'm using Zed Shaw's "Learn Python 3 The Hard Way"; the problem exercise is on page 16, and refers to counting eggs:

    print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)


    The author says the answer is 6.75, and if I drop those numbers into a Python shell I can easily confirm that. I accept that using the PEMDAS principle the method would be to bracket up the numbers, so I calculate in the right order. But none of my various experiments have succeeded. How to go about this?

    Continue reading...

Compartilhe esta Página