On 26/07/13 12:22, Saad Javed wrote:
WEAPONS = 'Rock', 'Paper', 'Scissors'
if cpu != player: if (player - cpu) % 3 < (cpu - player) % 3: #How does this line work?
Try it in the interpreter... the two subtractions will always result in +/-1 or +/-2 >>> -2 % 3 1 >>> 2 % 3 2 >>> -1 % 3 2 >>> 1 % 3 1 Now see how those work in the if statement. It's not how I would implement it(*) but its neat enough and works. (*)I'd probably use a dictionary or look up table. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor