Advertisement
Guest User

Untitled

a guest
May 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. #coding:utf-8
  2.  
  3. num = (int(input("Digite um nº: ")))
  4. primo = True
  5.  
  6. if num == 0 or num ==1 or num == 2:
  7.     primo = True
  8. else:
  9.     if num % 2 == 0:
  10.         primo = False
  11.     else:
  12.         inicio = 3
  13.         while (inicio < num) and primo == True:
  14.             if num % inicio == 0:
  15.                 primo = False
  16.             else:
  17.                 inicio = inicio + 2
  18.                 primo = True
  19.  
  20.         if primo == True:
  21.             print("O nº %d é primo!" %(num))
  22.         else:
  23.             print("O nº %d NÃO é primo!" %(num))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement