This program will check whether a given number is Prime or Not, in this program we will divide the number from 2 to square root of that number, if the number is divided by any number in b/w then the number will not be a prime number.
We are implementing this program using the concept of classes and objects.
Firstly we create the Class with Check name with 1 attributes ('number') and 2 methods, the methods are:
- Constructor Method: This is created using __init__ inbuilt keyword. The constructor method is used to initialize the attributes of the class at the time of object creation.
- Object Method: isPrime() is the object method, for creating object method we have to pass at least one parameter i.e. self keyword at the time of function creation.
Secondly, we have to create an object of this class using a class name with parenthesis then we have to call its method for our output.
Python code to check whether a given number is prime or not
Output
need an explanation for this answer? contact us directly to get an explanation for this answer