Returns the count of the numbers from 1 to N, inclusive, that are divisible by argument a or argument b, but not both

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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)

Expert Solution
Step 1 : algor

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

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Counting Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education