Home » Python » Python programs

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

Here, we will learn **how to find the sum of all numbers below 1000 which are multiples of 3 or 5 in the Python programming language?**

Submitted by Bipin Kumar, on December 06, 2019

Sometimes, we need to find the sum of all integers or numbers that are completely divisible by 3 and 5 up to thousands, since thousands are a too large number that’s why it becomes difficult for us. So, here we will do it in Python programming language that solves the problem in just a few seconds. To solve this problem, we will use the range function. So, before going to find the sum we will learn a little bit about range function.

**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)

It takes three arguments to start, stop, and step and it depends on users choose how they want to generate a sequence of numbers? By default range() function takes steps 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

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.