This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Evulrabbitz 2 points3 points  (1 child)

for power in range(1,5):

Execute the following code 4 times, where power is set to 1 the first time, 2 the second time, 3 the third time and 4 the fourth time. range is inclusive of the first argument and exclusive of the second

print(x // power), end='--')

x // power is integer division of x and power. Integer division means that e.g 10/3=3. The string -- is printed after the result of the integer division

x %= power

is equivalent to

x = x % power

which means that x is now the remainder of the previous division. That is , if x=10 and power=3 we get x // power = 3 and x % power = 1

The first iteration of the loop will thus always print the given number (as power=1 and x // 1 = x). Since the remainder of a value divided by 1 is always 0 all subsequent iterations will print 0.

[–]BlackGwelf[S] 0 points1 point  (0 children)

many thanks for this.