
What are the factors of 30? We can answer this question by writing a simple python script to give us the answer. Recall that a Factor in this case is a number that divides another number with no remainder. See our Python code below:
x = 30
print(f"The factors of {x} are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
#The factors of 30 are:
#1
#2
#3
#5
#6
#10
#15
#30
Let’s explain what is happening here:
- First we declare variable x to which we assign the value of 30.
- We declare an f-string that will explain the output that we will produce in the next statement.
- We write a loop that will output only the numbers that will divide by 30 and leave a reminder of 0.
Executing this code will give us the following output:
1, 2, 3, 5, 6, 10, 15, 30
We can do another example and find the factors of 25.
x = 25
print(f"The factors of {x} are:")
for i in range(1, x + 1):
if x % i ==
print(i)
#The factors of 25 are:
#1
#5
#25
And then we get:
1, 5, 25
Finally we can find the factors of 28:
x = 28
print(f"The factors of {x} are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
#The factors of 28 are:
#1
#2
#4
#7
#14
#28
And then we get:
1, 2, 4, 7, 14, 28
See how easy that was? Thanks for reading. 👌👌👌 Find out more about factors in math HERE.