#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Jun 7 15:18:32 2023 @author: richardson """ import math # code to input a number: nnst = input("Give me an integer here: ") nn = int(nnst) #nn = 186711 # this assigns nn to be an integer. print("Do you think "+str(nn)+" is prime?") # these are strings; print displays it as output. lastj = int(math.sqrt(nn)); # only need to check divisibility of numbers up to the square root of nn flagIfPrime = True for j in range(2,lastj+1): # range(2,nn) means the integers 2,3,4,...,lastj-1 # each time through the loop, j becomes 2, then 3, then 4, ... # and the loop is run lastj-2 times. if nn%j==0: # need two = signs if you are checking if an equation is true are not. # a==b means True if a=b, False if a!=b. '!=' means not equal. # nn%j means nn mod j = remainder when nn is divided by j. print('It turns out that '+str(nn)+' is not prime') flagIfPrime = False break #this makes the for loop stop. "break" cuts you out of any loop #print(j) if flagIfPrime: # if it went all the way through the for loop # and the last nn/j is not an integer. print("Guess what? The number "+str(nn)+" is prime.")