arrow_back Powrót do aplikacji

Factors of Natural Number

INTRODUCTION

Remember division with remainders. If we divide 13 by 4, we get 3 and remainder 1:

$13 : 4 = 3 r.1$

Sometimes when you divide one number by another, you get a remainder of zero. For example:

$15 : 5 = 3 r. 0$

If the remainder of the division is zero, then in the above example we will call 5 the factor (divisor) of 15.

EXAMPLE
We will write factors (dividers, divisors) of the number 12:

$F_{12}=\{1, 2, 3, 4, 6, 12\}$


PYTHON CODE

See in Google Colaboratory


HOW THE CODE WORKS?

  1. The program gets a number from the user using a function input.
  2. If the number is less than or equal to zero or not an integer, the program displays an appropriate error message.
  3. If the number is valid, the program creates an empty list ‘factors’ which will hold the divisors of the number.
  4. The program loops through the integers from 1 to the number entered by the user (inclusive) using a for loop. Checks whether the entered number is divisible without remainder by the current number in the iteration. If so, the current number is added to the factors list.
  5. After reviewing all the numbers, the program displays the divisors of the entered number on the screen.

LINKS

https://en.wikipedia.org/wiki/Divisor

arrow_back Powrót do aplikacji