In: Computer Science
Programming language in Python
Suppose, for Jane, n1 = 3, n2 = 4, and n3 = 5. Also
suppose, Jane iterates the number from 1 to 15.
At the beginning, Jane sets count to 0, and then proceeds
iterating the number from 1 to 15 and for each iteration does the
following:
for 1, count is increased by 1 because it is not divisible
by 3, 4, and 5; count is now: 1
for 2, count is increased by 2 because it is not divisible
by 3, 4, and 5; count is now: 3
for 3, count is increased by 1 because it is divisible by
3; count is now: 4
for 4, count is increased by 2 because it is divisible by
4; count is now: 6
for 5, count is increased by 3 because it is divisible by
5; count is now: 9
for 6, count is increased by 1 because it is divisible by
3; count is now: 10
for 7, count is increased by 7 because it is not divisible
by 3, 4, and 5; count is now: 17
for 8, count is increased by 2 because it is divisible by
4; count is now: 19
for 9, count is increased by 1 because it is divisible by
3; count is now: 20
for 10, count is increased by 3 because it is divisible by
5; count is now: 23
for 11, count is increased by 11 because it is not
divisible by 3, 4, and 5; count is now: 34
for 12, count is increased by 1 because it is divisible by
3, count is increased by 2 because it is divisible by 4; count is
now: 37
for 13, count is increased by 13 because it is not
divisible by 3, 4, and 5; count is now: 50
for 14, count is increased by 14 because it is not
divisible by 3, 4, and 5; count is now: 64
for 15, count is increased by 1 because it is divisible by
3, count is increased by 3 because it is divisible by 5; count is
now: 68
The final answer should be: 68
Please note: for 12, because it was divisible by both n1,
and n2, both 1 and 2 were added. Similarly,
for 15, because it was divisible by both n1 and n3, both 1
and 3 were added.
Please look at my code and in case of indentation issues check the screenshots.
--------------main.py---------------
def main():
n1 = 3
#initialize values of n1, n2, n3
n2 = 4
n3 = 5
count = 0
#intialize count to 0
for i in range(1, 16):
#loop from i = 0 to i =
15
divisible = False
#to check
if any one number out of n1, n2, n3 divides i
if i % n1 == 0:
#if n1 divides i, increase count by 1
count = count +
1
divisible =
True
if i % n2 == 0:
#if n2 divides i, increase count by 2
count = count +
2
divisible =
True
if i % n3 == 0:
#if n3 divides i, increase count by 3
count = count +
3
divisible =
True
if not divisible:
#if none
of the number divides i
count = count +
i #then increase
count by i
print("i =", i, ", count =",
count)
main()
----------Screenshots--------------------
----------Output--------------
------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs
down.
Please Do comment if you need any clarification.
I will surely help you.
Thankyou