# PURPOSE: to see if a user entered number (n) is prime or not prime
#
# INPUT(S): a number greater than 2. (n>2)
#
# OUTPUT(S): prime or not prime depending on what (n) is.
#
# EXAMPLES:input:  ;output:
#          input:  ;output:
################################################################################
import math

def prime(n):
    
    for i in range(2, int(n**0.5)+ 1):
        if n % i == 0:
            return False
    return True

def main():
    n = input('Enter a number: ')
    
    p = prime(n)

    while p is True:
        break
        print "The number you entered is prime."

    while p is False:
            break
            print "The number you entered is not prime." 

main()

i think there is something wrong with my print statements but i've tried tweaking them several diffferent ways and an indentation error pops up. the only way my code hasn't received errros is how it is but it doesn't print whether or not the (n) is prime. any suggestions?

Trying putting the break statement after the print statement

Modify your program to use if/else statements ...

# PURPOSE: to see if a user entered number (n) is prime or not prime
#
# INPUT(S): a number greater than 2. (n>2)
#
# OUTPUT(S): prime or not prime depending on what (n) is.
#
# EXAMPLES:input:  ;output:
#          input:  ;output:
################################################################################
#import math

def prime(n):
    
    for i in range(2, int(n**0.5)+ 1):
        if n % i == 0:
            return False
    return True

def main():
    n = input('Enter a number: ')
    
    p = prime(n)
    
    if p == True:
        print "The number you entered is prime."
    else:
        print "The number you entered is not prime." 

    
main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.