Question
Using Python 3: Assume a isPrime(n) function is given, write a program that generates a list of 10,000 integers from 1 to 10,000, then create
Using Python 3:
Assume a isPrime(n) function is given, write a program that generates a list of 10,000 integers from 1 to 10,000, then create 5 processes, and let each process take 5000 numbers respectively and check one by one, if a number is a prime number the result is 1, if not a prime number, the result is 0. For example, in a list [1, 2, 3, 4, 5], the result is a list of [0, 1, 1, 0, 1]. Your final result is a list of 10,000 0s or 1s.
from math import sqrt
def isPrime (n) :
if n <= 1 :
return 0
for fac in range (2, int(sqrt(n))+1) :
if n % fac == 0 :
return 0
return 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started