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')

6th Jun 2021, 1:02 PM
Tanmay Bapna
Tanmay Bapna - avatar
9 Respostas
+ 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')
6th Jun 2021, 1:30 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 3
By putting the link to playground, I meant this: https://code.sololearn.com/c9vwsI1m5rli/?ref=app
6th Jun 2021, 1:31 PM
Lisa
Lisa - avatar
+ 3
Tanmay Bapna comment 'break' ...
6th Jun 2021, 1:40 PM
Michail Getmanskiy
Michail Getmanskiy - avatar
+ 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)
6th Jun 2021, 1:20 PM
Lisa
Lisa - avatar
+ 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')
6th Jun 2021, 1:23 PM
Tanmay Bapna
Tanmay Bapna - avatar
+ 2
Sure
6th Jun 2021, 1:32 PM
Tanmay Bapna
Tanmay Bapna - avatar
+ 2
Thank you guys
6th Jun 2021, 1:34 PM
Tanmay Bapna
Tanmay Bapna - avatar
+ 1
Michail But I want each multiple of non-prime numbers in output
6th Jun 2021, 1:38 PM
Tanmay Bapna
Tanmay Bapna - avatar
+ 1
Thanks
6th Jun 2021, 1:42 PM
Tanmay Bapna
Tanmay Bapna - avatar