Project Euler Solutions
December 20, 2007 4 Comments
Head to Project Euler to solve mathematical problems using programming. I am cheating. I should not post these solutions but I want to get feedback on the quality of solutions implemented. The results are correct but are they generated from “quality” code? Only by sharing the code can I and others know.
Why am I using Python? Because this way I can learn how to program in it. Plus I get to learn more math.
import sys def multipleof (multiple = 1, integer = 1): try: return
(int(int(multiple) % int(integer)))
except: print 'error for multiple %s and integer %s' % (multiple, integer) print 'error was', sys.exc_info() raise sum = 0 for multiple in range (1, 1000): try: if multipleof (multiple, 3) == 0 or multipleof (multiple, 5) == 0: sum += multiple except: pass print 'The sum is ', sum