Home > Problem, Projects/Experiments, Python > Python: Multiples of Numbers

Python: Multiples of Numbers



Python: Multiples of 3 and 5
Problem No.1 in ProjectEuler

This is very easy, very short task to work on, the task as is in ProjectEuler like this “Find the sum of all the multiples of 3 or 5 below 1000.”

My way, as i like to do open code works for any numbers, we will ask the user to enter three numbers, num1 and num2 will be as (3 and 5) in the task, my_range will be as the 1000. So the code can get the sum Multiples of any two numbers in a ranges from 1 to my_range.

Check the answer if you like.













The Code:


# Multiples of 3 and 5
# ProjectEuler: Problem 1

def Multiples_of_N (num1,num2,my_range):

tot=0

for t in range (1,my_range):

if t %num1==0 or t%num2 ==0 :

tot = tot + t

return tot

print ‘\nDescription: This function will take three variables, two numbers represint the what we want to get there Multiples, then we ask for a range so we will start from 1 to your range.\n’
num1=int(input(‘Enter the first number:’))
num2=int(input(‘Enter the second number:’))
my_range =int(input(‘Enter the range (1, ??):’))

total=Multiples_of_N (num1,num2,my_range)

print ‘\nYou entered ‘,num1,’,’, num2,’ So the sum of all multiples of those number in range (1-‘,my_range,’) = ‘,total






Follow me on Twitter..



  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s