Skip to content

Instantly share code, notes, and snippets.

@tarsisazevedo
Created May 16, 2011 01:19
Show Gist options
  • Save tarsisazevedo/973755 to your computer and use it in GitHub Desktop.
Save tarsisazevedo/973755 to your computer and use it in GitHub Desktop.
from unittest import TestCase
from primos import num_eh_primo
class Test10001Primos(TestCase):
def test_achar_sexto_primo(self):
self.assertEquals(13, achar_n_primo(n=6))
def test_achar_10001_primo(self):
self.assertEquals(104743, achar_n_primo(n=10001))
def achar_n_primo(n):
flag = 0
numero = 0
while flag != n:
if num_eh_primo(numero):
flag += 1
if flag == n:
break
numero += 1
else:
numero += 1
return numero
@tarsisazevedo
Copy link
Author

def num_eh_primo(num):
    if num <= 1:
        return False

    for i in range(2,num):
        if num % i == 0:
            return False
    return True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment