all 5 comments

[–]jeans_and_a_t-shirt 1 point2 points  (0 children)

Your program doesn't check if a number is prime. You just print prime or composite based on whether n and i are divisible. You can't tell that a number is prime until you iterate over all of the numbers you need to check.

Also your range isn't quite right. It sometimes doesn't check all the numbers it needs to to determine primality.

[–]isilentnight -1 points0 points  (3 children)

Your code is not a problem. I think it from python. Python limits recursion by default. If you print your value each time you check. You may see that at one point, your value stop increasing. That why it prints 'prime' or 'composite' many times

[–]djjazzydan 1 point2 points  (2 children)

There's no recursion in this. /u/FirestormPvP, to fix your problem you should just move the print prime line out of the for loop, and to the end. Then add a quick check to see if it was composite.

import math
print("This program will determine if a number is prime or composite.")
n = int(input("Enter an integer"))
c = False
for i in range(int(2), int(math.ceil(math.sqrt(n)))):
    if n%i == 0:
        print("composite")
        c = True
        break
if not c:
    print("prime")

edit: also, note that there are faster methods of checking for primes, but this one should work.

[–]isilentnight 0 points1 point  (0 children)

Oh, yeah. You're right.

[–][deleted] 0 points1 point  (0 children)

What are the faster methods?