Returns the count of the numbers from 1 to N, inclusive, that are divisible by argument a or argument b, but not both
import unittest
# ------------------------------------------------------------
def enumerate6(N, a, b) :
'''
Assumes that N, a, b are positive integers.
Returns the count of the numbers from 1 to N, inclusive,
that are divisible by argument a or argument b, but not both
For example, enumerate6(10, 2, 5) returns 5,
since 2, 4, 5, 6, 8 are the numbers from 1 to 10 that
are divisible by 2 or 5 but not both
'''
pass
# --------------------------------------------------------------
# The Testing
# --------------------------------------------------------------
class myTests(unittest.TestCase):
def test1(self):
ans = enumerate6(10, 2, 5)
self.assertEqual(ans, 5)
def test2(self):
ans = enumerate6(12, 2, 5)
self.assertEqual(ans, 6)
def test3(self):
ans = enumerate6(5000, 4, 2)
self.assertEqual(ans, 1875)
def test4(self):
ans = enumerate6(50000, 3, 8)
self.assertEqual(ans, 18750)
def test5(self):
ans = enumerate6(12131, 7, 2)
self.assertEqual(ans, 6066)
if __name__ == '__main__':
unittest.main(exit=True)

1. run loop from 1 to N (in python we have to use range(1,N + 1))
2. set Boolean flag1 = True if i is divisible by a else False
3. set Boolean flag2 = True if i is divisible by b else False
4 check if both are unequal
5. if true increment counter
6.else continue the loop
7.after loop return the counter value
Note : in you unittest test3 has wrong actual value .
the total number in range of (1,5000) if 1250 because 2 will divide 2500 numbers among this. while 4 will divide
half of them i.e 1250 so there is only 1250 element which is divided by 2 but not by 4 but there is no element which
is divisible by 4 but not divisible by 2. so actual output is 1250
Step by step
Solved in 4 steps with 2 images









