- 1
Returning '9' as prime no.
6 Réponses
0
Make the loop stop after detecting non-prime by inserting a break statement in line 6.
Lines 7, 8 should be unindented by one level to make it a for/else statement. Then delete line 9.
+ 1
Please always tag the language you're asking about.
https://code.sololearn.com/W3uiji9X28C1/?ref=app
0
Yes. Else part executed if if-part fails.
9%2==0 is false then print and breaks
Find logic of printing else only when never if part executed.
0
Just iterate ur code by giving value 9 u will find ur mistake
0
Ident or move break statement into if-block. Its correctly outside if.
0
Add an else: continue block to check the next values before getting to the break statement.
https://code.sololearn.com/cI7YSZ0hVttm/?ref=app
Also try not to use "no." as an abbreviation for number, because it is easily confused with no, specially in small phone screens.
There is a module called primefac that you can pip install and does prime factorization if that is what you want.
More ways of checking if a number is prime:
https://www.pythonpool.com/check-if-number-is-prime-in-JUMP_LINK__&&__python__&&__JUMP_LINK/