+ 4
A simple way to do this would be to use a boolean variable in your function then in your loop set it to True/False and add an if statement to the end of the function to check the boolean value.
def factors(a):
has_factors = False
for i in range(2,a):
if a%i==0:
q=a/i
has_factors = True
print(int(q),"x",i)
if not has_factors:
print(a , "does not have any factors")