you are here->home->Class 11->Prime or Not
Prime or Not

# Objective

To implement a Python program that checks whether the given number is a prime number or not.

# Theory

A prime number is a positive integer greater than 1, that has no positive integer divisors other than 1 and itself. In other words, a prime number can only be divided evenly by 1 and itself. These numbers are important in many areas of mathematics including number theory, cryptography and computer science.

Here are some examples of first few prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29.

Number 6 is not a prime number because it can be evenly divided by either 2 or 3.

# Instructions

The program finds whether the given number is a prime and its equivalent low-level language instructions executed by the hardware. The low-level language instructions used are:

 assign It assigns a value to a variable. div It divides the values contained in two registers and puts the result in the first register. eq It checks if the values contained in two registers are same. if_false Checks if the condition evaluated to be false. if_true Checks if the condition evaluated to true. in It reads the input from the user and stores it in a variable. incr It increases the value contained in the register by 1. label Is used to mark the position in the low-level instructions to enable jumping to the marked position. load It loads a value of a global or local variable to the given register. lte Lesser than or equal to operator, check whether the first operand is lesser than second operand and return a boolean value based on the condition. out It prints the output value to the screen. rem It performs division operation of the values contained in two registers and puts the remainder in the first register. store It stores the value from the given register to the global or local variable.

# Learning Outcomes

• Gain insight into the basic mathematical logic of prime numbers and how it is implemented in the program.
• Understand the logic for checking whether a number is prime or not by iterating through potential divisors.
• Understand the use of ‘break’ statement to exit from the loop.
• To learn about various conditional (>= ,<= and ==) and arithmetic (+, %) operators available in Python.