-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
46 lines (41 loc) · 975 Bytes
/
util.py
File metadata and controls
46 lines (41 loc) · 975 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
42
43
44
45
46
#!/usr/bin/env python
# coding: utf-8
import random
# Cria matriz com numeros aleatorios
def criaMatriz(tam):
matriz = []
if tam>0:
for i in range(tam):
linha = []
for j in range(tam):
num = random.randint(1,99999)
linha.append(num)
matriz.append(linha)
return matriz
# Imprimir matriz
def printMatriz(matriz):
tam = len(matriz)
#print(tam)
print('-------MATRIZ-------')
for i in range(tam): # range(n) -> [0..n-1]
for j in range(tam):
print('{}\t'.format(matriz[i][j]))
print('\n')
print('-------')
pass
# Se o num é primo
def isPrime(n):
# É divisível só por 1 e ele mesmo?
div = 0 # Quantidade de divisores desse número
for i in range(1,n+1): # n+1 devido range(a,b) compreende [a..b-1]
if n%i==0:
div += 1
#print(div)
return True if div==2 else False
# Conta primos em uma lista
def countPrime(lista):
counter = 0
for number in lista:
counter += 1 if isPrime(number) else 0
#print(counter)
return counter