+ 3
I want to ask why is 9, 25, and 49 still prints the output? They are not prime numbers
6 Réponses
+ 4
There was some indentation errors and an extra while loop where an if was all that was required.
Here is the corrected code:
numb = 49
if (numb<100):
numb2 = 2
while (numb2 <= (numb / numb2)):
if not (numb % numb2):
print(numb," is not a prime.")
break
numb2 += 1
if (numb2 > (numb/numb2)):
print(numb, " is a prime.")
break
else : print("Your Number exceeded 100")
+ 3
Use a loop.
First convert the code into a function, and then in a loop from 1 to 100, run the function for each number. The program will then print the numbers.
Here is a code for the same.
def prime(numb):
if numb==1: return
numb2 = 2
while (numb2 <= (numb / numb2)):
if not (numb % numb2):
break
numb2 += 1
if (numb2 > (numb/numb2)):
print(numb, " is a prime.")
for i in range(1,100): prime(i)
+ 1
thank you for the corrected code. but how i will make it to print every prime number < 100?
+ 1
so for loop is the answer?
+ 1
thank you very much.. i will study the code..
+ 1
thanks for the help
https://code.sololearn.com/cs94TQcK7Cpv/?ref=app