0
Please help me to debug this python code
Please run the program and then check error for n in range(1,10): for x in range(2,n): if n % x == 0: print(n,'equals',x,'*',n//x) else: print(n,'is a prime number')
9 Answers
+ 3
for n in range(1,10):
p = True
if n>2 :
for x in range(2,n):
if n % x == 0:
print(n,'equals',x,'*',n//x)
p = False
break
if p:
print(n,'is a prime number')
+ 3
By putting the link to playground, I meant this:
https://code.sololearn.com/c9vwsI1m5rli/?ref=app
+ 3
Tanmay Bapna comment 'break' ...
+ 2
Hint:
in case the if-statement evaluates "True", the number is not a prime, so we need to skip the else part in the end and go straight to the next n
(You can put your code in playground and then share the link â so debugging is easier)
+ 2
for n in range(1,10):
for x in range(2,n):
if n % x == 0:
print(n,'equals',x,'*',n//x)
else:
print(n,'is a prime number')
+ 2
Sure
+ 2
Thank you guys
+ 1
Michail But I want each multiple of non-prime numbers in output
+ 1
Thanks