New course! Every coder should learn Generative AI!
Try a free lesson0
How can i print number if it does not have any factors??
program is simple just checking whether the given number is divisible by any number. if it is divisible print quotient and divisor don't have any idea about how to print if number is not divisible by any thing https://code.sololearn.com/cX8ByHbBsMOt/?ref=app
2 Answers
+ 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")
+ 1
thank you sir