1) Define a function lt(m), which generates a list of m random integers between 1 and 200. The function is to generate a list of m random integers between 1 and 200. 2) Define a function prime(n) to determine whether the integer n is prime. 3) Use the LT function to generate a list LS composed of 12 positive integers between 1 and 200, and then use the prime function to find out the prime number in the list and output it. At the same time, calculate the sum of the prime numbers and output it. The display format is as follows (the randomly generated data will be different, please refer to the output format) : IMPORT RANDOM
Determine whether the integer n is prime
def prime(n):
Flag =True#flag =True#flag =True#flag for I in range(2,n): if n% I ==0: flag=False# return 0 break# else: return 1
Generate m random numbers in the range [1-200] and place them in the list <
def lt(m):
Ls =[random. RandInt (1200) for I in range(m)] return ls
Generates a list of 12 positive integers between 1 and 200 called ls
Ls print(” Random list is :”,ls)# print(” Primes have :”, end=””)#end=”
Find the sum of prime numbers
s=0
for i in ls:
Print (I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")# print(I,end=" ")#
Print (“\n: “,s)