[Tutor] help with prime number program
andrade1@umbc.edu
andrade1 at umbc.edu
Sun Oct 30 17:37:42 CET 2005
Hello
I am trying to write a program that will figure out if a number is prime
or not. Currently this is the code that I have:
import math
def main():
number=input("Please enter a positive whole number greater than 2: ")
for value in range(2, number-math.sqrt):
if number % value == 0:
print number, "is not prime"
exit
print number, "is prime"
main()
my problem is that the output prints both statements whether the number is
prime or not. How could I get it to only print the one statement saying
that 49 is not a prime number?
enter a number greater than 2: 49
49 is not prime
49 is prime
More information about the Tutor
mailing list