Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: Circular Prime: Python Code : Problem 35

Sunday, August 17, 2014

Circular Prime: Python Code : Problem 35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
Write a program to check entered number is a Circular prime or not.
First few Circular Primes are

2,3,5,7,11,13,17,31,37,71,73,79,97,113,131,197,199,311,337,373,719,
733,919,971,991,1193,1931,3119,3779,7793,7937,9311,9377,11939,
19391,19937,37199,39119,,71993,91193,93719,93911,99371,193939,199933,
319993,331999,391939,393919,919393,933199,939193,939391,993319,999331

FOR JAVA CODE CLICK HERE

Python  Code

def CircularPrime():
    numb = int(input("Enter the number:"))
    flagCircular = True
    def CheckPrime(numb):
        flag = True
        for i in range(numb//2):
            i = i+2
            if numb%i == 0:
                flag = False
                break
        if flag == True:
            return True
        else:
            return False
    for i in range(len(str(numb))):
        if CheckPrime(numb) == True:
            flagCircular = True
        else:
            flagCircular = False
            break
        stringNumb = str(numb)
        firstDigit = stringNumb[0]
        tmpNumb =""
        for j in range(len(str(numb))-1):
            tmpNumb    += stringNumb[j+1]
        tmpNumb += stringNumb[0]
        numb = int(tmpNumb)
    if flagCircular == True:
        print ("Entered number is a Circular Prime")
    else:
        print ("Entered number is not not Circular Prime")
CircularPrime()

1 comment:

  1. JAVA CODE FOR CIRCULAR PRIME: https://thecprojectt.blogspot.com/2019/03/isc-computer-science-practical-2016.html

    ReplyDelete