Number 2520?

number-2520Did you know that 2520 is the smallest number exactly divisible by all integers from 1 to 10.

The aim of this challenge is to write a python script to work out this number from its definition.

Note that a number (a) is exactly divisible (whole division) by another number (b) if the remainder of divising a per b is equal to 0.

In pseudo code:

a = INPUT("Type a whole number (integer)")
a = INPUT("Type another whole number (integer)")
IF (a MOD b) == 0 THEN
   OUTPUT(a + " is exactly divisible by " + b)
ELSE
  OUTPUT(a + " is not exactly divisible by " + b)
END IF

In Python the MOD operator (remainder) is %.

a = int(input("Type a whole number (integer)"))
b = int(input("Type another whole number (integer)"))
if (a % b) == 0:
   print(str(a) + " is exactly divisible by " + str(b))
else:
  print(str(a) + " is not exactly divisible by " + str(b))

We are going to use this operator in our code to find out the smallest number exactly divisible by all integers from 1 to 10.

Note that we know, per definition, that this number will have to be greater or equal to 10. So, using an iterative approach (in this case, a while loop) we will test every number from 10, one at a time up until we find a number that is divisible by all the numbers from 1 to 10.

Flowchart


Here is the flowchart of our algorithm:
number-2520-flowchart

Python Code


You can use the above flowchart to recreate the Python code in the trinket window below:

Did you like this challenge?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 13

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: