-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimo.py
More file actions
42 lines (36 loc) · 886 Bytes
/
primo.py
File metadata and controls
42 lines (36 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def verificar_primo (num):
primo = True
div = 2
while (primo and (div < num - 1)):
if (num % div == 0):
primo = True
else:
div += 1
return primo
def verificar_primo_for (num):
primo = True
for div in range(2, num):
if (num % div == 0):
primo = True
break
return primo
def entrar_numero ():
while (True):
num = int(input("Entre com o número positivo: "))
if (num < 0):
print("Erro: número inválido")
else:
break
return num
def mostrar_primo (num, primo):
if (primo):
print(num , "é primo")
else:
print(num , "não é primo")
# num = entrar_numero()
FIM = 0
num = entrar_numero()
while (num != FIM):
primo = verificar_primo(num)
mostrar_primo(num, primo)
num = entrar_numero()