Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

I have written the following program in python and am new to programming in Python. I am looking for suggestions for making efficient programs and developing good programming habits.

import math
data ={}
def isPrime(n):
 global data
 if n in data:
 return data[n]
 for num in range(2,math.floor(math.sqrt(n)+1)):
 if n%num == 0:
 data[n]=False
 return False
 data[n]=True
 return True
count =0
data ={}
for num in range (2,1000000):
 q=False
 num=str(num)
 for i in range(len(num)):
 if (isPrime(int(num[i:]+num[:i]))):
 q=True
 else:
 q=False
 break
 if q: 
 count+=1 
print (count) 

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

I have written the following program in python and am new to programming in Python. I am looking for suggestions for making efficient programs and developing good programming habits.

import math
data ={}
def isPrime(n):
 global data
 if n in data:
 return data[n]
 for num in range(2,math.floor(math.sqrt(n)+1)):
 if n%num == 0:
 data[n]=False
 return False
 data[n]=True
 return True
count =0
data ={}
for num in range (2,1000000):
 q=False
 num=str(num)
 for i in range(len(num)):
 if (isPrime(int(num[i:]+num[:i]))):
 q=True
 else:
 q=False
 break
 if q: 
 count+=1 
print (count) 

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

I have written the following program in python and am new to programming in Python. I am looking for suggestions for making efficient programs and developing good programming habits.

import math
data ={}
def isPrime(n):
 global data
 if n in data:
 return data[n]
 for num in range(2,math.floor(math.sqrt(n)+1)):
 if n%num == 0:
 data[n]=False
 return False
 data[n]=True
 return True
count =0
data ={}
for num in range (2,1000000):
 q=False
 num=str(num)
 for i in range(len(num)):
 if (isPrime(int(num[i:]+num[:i]))):
 q=True
 else:
 q=False
 break
 if q: 
 count+=1 
print (count) 
added 10 characters in body
Source Link
yask
  • 245
  • 2
  • 9

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

I have written the following program in python and am new to programming in Python. I am looking for suggestions for making efficient programs and developing good programming habits.

import math
data ={}
def isPrime(n):
 global data
 if n in data:
 return data[n]
 for num in range(2,math.floor(math.sqrt(n)+1)):
 if n%num == 0:
 data[n]=False
 return False
 data[n]=True
 return True
count =0
data ={}
for num in range (2,1000000):
 q=False
 num=str(num)
 for i in range(len(num)):
 if (isPrime(int(num[i:]+num[:i]))):
 q=True
 else:
 q=False
 break
 if q: 
 count+=1 
print (count) 

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

I have written the following program in python and am new to programming. I am looking for suggestions for making efficient programs and developing good programming habits.

import math
data ={}
def isPrime(n):
 global data
 if n in data:
 return data[n]
 for num in range(2,math.floor(math.sqrt(n)+1)):
 if n%num == 0:
 data[n]=False
 return False
 data[n]=True
 return True
count =0
data ={}
for num in range (2,1000000):
 q=False
 num=str(num)
 for i in range(len(num)):
 if (isPrime(int(num[i:]+num[:i]))):
 q=True
 else:
 q=False
 break
 if q: 
 count+=1 
print (count) 

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

I have written the following program in python and am new to programming in Python. I am looking for suggestions for making efficient programs and developing good programming habits.

import math
data ={}
def isPrime(n):
 global data
 if n in data:
 return data[n]
 for num in range(2,math.floor(math.sqrt(n)+1)):
 if n%num == 0:
 data[n]=False
 return False
 data[n]=True
 return True
count =0
data ={}
for num in range (2,1000000):
 q=False
 num=str(num)
 for i in range(len(num)):
 if (isPrime(int(num[i:]+num[:i]))):
 q=True
 else:
 q=False
 break
 if q: 
 count+=1 
print (count) 
edited tags
Link
SylvainD
  • 29.8k
  • 1
  • 49
  • 93
edited tags
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
Loading
edited tags
Link
SylvainD
  • 29.8k
  • 1
  • 49
  • 93
Loading
Source Link
yask
  • 245
  • 2
  • 9
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /