0
Where am I making mistake
https://code.sololearn.com/c5IiiG14Aqjm/?ref=app irrelevant results are appearing when I want to find prime for 49 81 121 169 289
5 Answers
+ 1
In your else block, you need to add
if i==num1:
[print(...)]
so
13: else:
14: if i==num1:
15: print(num,â is a prime number.â)
As it stands, every time you test for whether i divides your number, if it doesnât, your code says immediately that the number is prime. Adding that if statement in means that it will onlt declare the number as prime if it has reached the end of the loop and still not found a number that divides num.
+ 1
You could put your print statements out of the loop:
import math
num = int(input("Enter the number" + "\n"))
print("To find that the number", num, "is prime or not")
num1 = math.trunc(num**0.5)
print(num1)
j = 0
if num > 0:
for i in range(2,num1 +1):
if (num % i) == 0:
j = 1
break
if j == 1:
print("The number", num, "is not a prime number")
print( i, "times", num // i," gives the given number")
else:
print("The number", num, " is a prime number")
+ 1
0
thanx understood my mistake
0
lol I spent 1 day figuring ot