Sum of All Factors

Calculate sum of all factors of a number.

Logic BuildingIntermediate
Logic Building
# Take number
num = int(input("Enter a number: "))

# Sum factors
factor_sum = 0
for i in range(1, num + 1):
    if num % i == 0:
        factor_sum += i

print(f"Sum of factors: {factor_sum}")

Output

Enter a number: 12
Sum of factors: 28

Find all factors and sum them.

Key Concepts:

  • Find all factors
  • Add each factor to sum
  • Print total sum