Unit 2 Task 31 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 31: Is this number prime?

← Back to task


One possible program:

number_to_check = int(input("n (>=2): "))
is_prime = True

for divisor in range(2, number_to_check):
    if number_to_check % divisor == 0:
        is_prime = False
        break

if is_prime:
    print("prime")
else:
    print("not prime")