Please be sure these tests work or else it is wrong: assert(nthCircularPrime(0)
ID: 3913225 • Letter: P
Question
Please be sure these tests work or else it is wrong:
assert(nthCircularPrime(0) == 2)
assert(nthCircularPrime(4) == 11)
assert(nthCircularPrime(5) == 13)
assert(nthCircularPrime(11) == 79)
assert(nthCircularPrime(15) == 197)
assert(nthCircularPrime(25) == 1193)
2. nthCircularPrime [70 pts] A circular prime is an integer number with the property that any rotation of that number's digits is prime. In this case, rotation refers to cycling the digits of a number; for example, the rotations of 1234 are 1234, 2341, 3412, and 4123. You can read more about this on the Wikipedia page. Single-digit primes are all circular, of course. To find the nth circular prime, you'll need to write isPrime and three other functions: 1. rotateNumber [20 pts] number's digits by one would turn the number 1234 to 4123. 2. isCircularPrime [30 pts] This function takes a non-negative integer number, x, and determines whether that number is a circular prime. To do this, you'll need to check whether every rotation of the number is prime. 3. nthCircularPrime [20 pts] This function takes a non-negative integer number n, and returns the nth circular prime.Explanation / Answer
Python3 Method:
def nthCircularPrime(n):
count = -1
m = 2
p = 2
while count < n:
if isCircularPrime(m):
p = m
count += 1
m += 1
return p