View this page "Problema 1: Números Primos"

4 views
Skip to first unread message

Toscano

unread,
Jan 28, 2010, 10:49:14 PM1/28/10
to Python: rumo a janela

Click on http://groups.google.com/group/python-rumo-a-janela/web/problema-1-nmeros-primos
- or copy & paste it into your browser's address bar if that doesn't
work.

Toscano

unread,
Jan 28, 2010, 11:25:35 PM1/28/10
to Python: rumo a janela
Minha resolução:

#Autor: Rafael Toscano

def Primo(a):
cont = 0
if(a<0):
a = a*(-1)# Caso especial em que os numeros sao negativos
if(a==1): # Caso especial em que o numero é 1
cont = cont + 1
for i in range(2,a):# Demais casos
if(a%i==0):
cont = cont + 1
if(cont>0):
print "Nao primo"
else:
print "Primo"
numero = int(raw_input("Digite um numero: "))
Primo(numero)

Reply all
Reply to author
Forward
0 new messages