How can i print number if it does not have any factors?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

26th Oct 2017, 7:50 PM
the terminator
the terminator - avatar
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")
26th Oct 2017, 8:17 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thank you sir
26th Oct 2017, 8:26 PM
the terminator
the terminator - avatar