I'm designing a program that prints prime factors of a number.
Here is the code:
while True:
x = int(input("Enter a positive number: "))
if x >= 0:
break
ranger = list(range(1, x+1))
counter = 0
#The first for loop checks if the number is a factor
for i in ranger:
if x % i == 0:
#The second for loop checks if the number is prime
for element in range(1, i+1 ):
if i % element == 0:
counter += 1
if counter == 2:
prime_factors = []
prime_factors += i
#Counter having a value of 2 means the number is prime
print(prime_factors)
I keep getting the error:
Traceback (most recent call last):
File ".\primefactors.py", line 18, in <module>
prime_factors += i
TypeError: 'int' object is not iterable
But I don't seem to understand why I am getting this error.