Last active
December 26, 2015 03:19
-
-
Save julius-datajunkie/7084889 to your computer and use it in GitHub Desktop.
There must be a faster way than simply iterating through all the numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
def SumMultiplesOfThreeOrFive(number): | |
return sum(i for i in range(1,number) if (i % 3 == 0 or i % 5 == 0)) | |
#for i in range(1,number): | |
# if (i % 3 == 0 or i % 5 == 0): | |
# sum += i | |
#return sum | |
class TestSumMultiplesOfThreeOrFive(unittest.TestCase): | |
def test_case(self): | |
self.assertEqual(SumMultiplesOfThreeOrFive(10),23) | |
if __name__ == '__main__': | |
unittest.main(exit=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment