I had a question about using the modulus operator in Python and whether I have used it in a understandable way.
This is how I've written the script:
#sum numbers 1 to 200 except mults of 4 or 7 def main(): sum = 0 for x in range(200+1): if (x % 4 and x % 7): #is this bad??? sum = sum + x print sum if __name__ == '__main__': main()
So my questions are:
- Should I spell out the modulo more clearly? ie
if x % 4 != 0 and x % 7 != 0
- Should I be approaching this in a very different way?