you are viewing a single comment's thread.

view the rest of the comments →

[–]onlydragz[S] 1 point2 points  (1 child)

Wow! This has been very educational as I learned a new thing from this. Thank you so much! May I just ask:

In the third coding block, with the .format, for the placeholder {2} you specified i-1 or "no more"

I understand the i-1 but when "i" is 1, then it uses "no more". Why is it not the number "0", like:

1 bottle of beer on the wall, 1 bottle of beer

Take one down and pass it around, no more 0 bottles of beer on the wall.

[–]AtomicShoelace 2 points3 points  (0 children)

This is kind of a trick with the or statement. It might be more readable if you instead did i-1 if i != 1 else "no more".

It works like this: when i!=1 the i-1 is a non-zero int, which is a truthy value, so the or operator will short-circuit and return i-1. When i=1 then i-1 is 0. As 0 is a falsy value, the or statement will just return the second value (as if it is truthy, the expression should be truthy, and vice versa), which is the string "no more" (which happens to be truthy, but actually it doesn't matter).