On 30/05/15 00:37, Cameron Simpson wrote:
def IsDivisibleBy3(number):#string variable return not int(number) % 3To illustrate that there isn't just One Right Way, I would code the above like this: def IsDivisibleBy3(number): #string variable return int(number) % 3 == 0 Alan's code relies on "not" using an expressions "nonzero"ness as a boolean value. I _much_ prefer to directly state the test instead of relying on magic numeric=>boolean effects.
In this case I do too. Especially since my version using the 'not' as well as implied Truth value is less clear for a beginner such as the OP. On reflection the explicit test is clearer. If the 'not' had not been necessary I'd have been happy without the == test. But introducing the not can be confusing. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
