Python programs to check whether the given number is prime or not using oops

 To check whether the given number is prime or not, using object oriented programs in python (oops). Following procedure you need to follow:-

1. Create a class check. (You can create whatever word you like to create a class).

2. While creating a objects of check class take  one users inputs.

3. Finally , the result will display whether the given input is prime or not.

What is prime number ?

A prime number is a natural number which is always greater than 1 and has no any positive divisors other than 1 and itself. some of the examples of prime number are { 2 , 3, 5, 7, etc.}

Let's implement the code:-


class Check:
   def __init__(self, number) :
      self.num = number
     
   def isPrime(self):
     for i in range (2, int(self.num **0.5) +1 ):
        if (self.num % i == 0):
           return ("This is  not a prime number")
        else:
           return ("This is a prime number")
Result = int(input("Enter the number:"))
check_prime = Check(Result)
print (check_prime.isPrime())
       


OUTPUT

Enter the number:

10

The given number is not a prime number


Enter the number:

7

The given number is a prime number


If you have any queries or suggestions, please feel free to ask. Thank You!

No comments:

If you have any doubts please let's me know

Powered by Blogger.