Variables in loops


In this question, l got 50 when I typed “number = max” but I got 75 after typing “max = number”.

Don’t they mean the same? Why do I get different outputs?

Thank you for your help!

When you assign something, the value on the right is stored in the variable on the left, meaning writing number = max means the number in the max variable will also be stored in the number variable. Since you’re returning the max variable, the first (and only) value its assigned is the first element of the nums list.

Conversely, when you write max = number, the value of number is then stored in max, meaning max is updated every time the loop reaches a bigger number.

Some code
num = 5
max = 7
num = max
#num is now 7, max is 7
max = 3
#num is still 7, max is 3
max = num
#num is still 7, max is now 7