Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Apr 20 10:54:47 2018
  4.  
  5. @author: joaoc
  6. """
  7. n=10
  8. x=0
  9. lista=[]
  10.  
  11.  
  12. def primo(x):
  13.    assert (type(x) is int)
  14.    i = 2
  15.    aux = 0
  16.    #res = x % i
  17.    while i!=x-1:
  18.     res = x % i
  19.     if res==0:
  20.         aux = 1
  21.         return 'não é primo'
  22.     i+=1
  23.     if aux == 0:
  24.         return 'é primo'
  25.  
  26.  
  27. def todosprimos():
  28.    x = 0
  29.    while x!=n-1:
  30.        if primo(x)=='é primo':
  31.            lista.append(x)
  32.  
  33.        x+=1
  34.  
  35.        
  36. def resposta():
  37.     return 'o 10001º numero primo é:',lista[:1]
  38.  
  39. if __name__ == "__main__":
  40.     todosprimos()
  41.  
  42.     print lista
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement