2
well I need to create a program in python using threads that find the largest number of primes in 60 seconds, but I cannot understand the use of threads for it:`
import time
import math
def is_prime(number):
number = int(number)
if number == 2:
return True
num_sqrt = int(math.sqrt(number))
if number:
if number % 2 == 0:
return False
for i in range(3, num_sqrt+1, 2):
if number % i == 0:
return False
return True
def func_Prime(i):
i = 0
numero = 3
print 'PROGRAMA QUE VERIFICA E MOSTRA QUAIS OS NÚMEROS PRIMOS.'
ini = time.time()
final = 0
while(final < 1):
numero = numero+1
resposta = is_prime(numero)
if resposta:
i = i+1
primo = numero
fim = time.time()
final = fim - ini
return primo, i
I did some tests here, and I changed some things in its function, now it is returning the amount of prime numbers given a time as parameter and it also returns the last prime number. I don’t know exactly what you want, because you need to compare the values, but as your function returns many prime numbers it is difficult to check one by one, so I assumed as a basis the last number returned by it checking if it is prime.
– gato
The
time
is used to measure the execution time, in this case it is being applied to determine how long the function will be calculating prime number.– gato
the function of this work is to use the threads to find as many primes as possible, the code returns the last prime number found and the quantity found in 60 seconds
– Marcelo Souza
The
time.time()
it is not a thread if I am not mistaken, have to consult the documentation.– gato
I’m confused about what you want and what your problem is.
– gato