Final answer:
To check if a number is prime, iterate through numbers from 2 to the square root of the number and check for divisibility. Implement a program to generate 20 random integers, check for primality, and find the count and sum of prime numbers.
Step-by-step explanation:
In order to check if a number is prime, we need to iterate through all numbers from 2 to sqrt(x) and check if x is divisible by any of these numbers. If x is divisible by any number within this range, then it is not prime. If x is not divisible by any number within this range, then it is prime. Here is an example implementation:
import math
import random
def is_prime(x):
if x < 2:
return False
for i in range(2, int(math.sqrt(x)) + 1):
if x % i == 0:
return False
return True
def main():
primes = []
count = 0
summation = 0
for _ in range(20):
num = random.randint(1, 1000)
if is_prime(num):
primes.append(num)
count += 1
summation += num
print(f'Prime numbers: {primes}')
print(f'Count of prime numbers: {count}')
print(f'Summation of prime numbers: {summation}')
main()