Find the sum of all numbers below 1000 which are multiples of 3 or 5 in Python

Discover the aggregate of all numbers beneath 1000 which are products of 3 or 5 in Python

Here and there, we have to discover the entirety all things considered or numbers that are totally separable by 3 and 5 up to thousands, since thousands are a too huge number that is the reason it gets hard for us.

In this way, here we will do it in Python programming language that takes care of the issue in only a couple of moments. To take care of this issue, we will utilize the range of work.

Along these lines, before going to discover the whole we will get familiar with a smidgen about range work.

What is the range work in Python?

The range() is a worked in work accessible in Python. In basic terms, the range enables them to create a progression of numbers inside a given interim.

This capacity just works with the whole numbers, for example, entire numbers.

Syntax of range() function:

    range(start, stop, step)

The linguistic structure of range() work:

It takes three contentions to start, stop, and step and it relies upon clients pick how they need to produce a succession of numbers?

Of course, go() work makes strides of 1.

Program:

# initialize the value of n
n=1000 
# initialize value of s is zero.
s=0 

# checking the number is divisible by 3 or 5
# and find their sum
for k in range(1,n+1):
    if k%3==0 or k%5==0: #checking condition 
        s+=k

# printing the result
print('The sum of the number:',s)

Output:

The sum of the number: 234168

Leave a Comment

error: Alert: Content is protected!!