Q:

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

belongs to collection: Python basic programs

0

What is the range function in Python?

The range() is a built-in function available in Python. In simple terms, the range allows them to generate a series of numbers within a given interval. This function only works with the integers i.e. whole numbers.

Syntax of range() function:

    range(start, stop, step)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | How can I force division to be floating p... >>
<< Draw a pie chart that shows our daily activity in ...