Question
the program should create two empty lists: prime and non_prime. For each random number, test to see if it is prime using the is_prime() function
the program should create two empty lists: prime and non_prime. For each random number, test to see if it is prime using the is_prime() function you wrote in the Prime Numbers lab. If the number is prime, append it to the prime list; if the number is non_prime, append it to the non_prime list. Print the two lists. Your output should be similar to this:
Primes: [47, 71, 61, 79, 57, 89, 3, 29, 41, 31] Non-primes: [22, 25, 28, 99, 86, 75, 98, 4, 22, 33]
so the code at the bottom is my code and I am having trouble appending the numbers in the empty list according to them being either a prime number or not. Please help?
#Jonathan Runyambo #02/24/2018 #Modify your program to create two empty lists: prime and non_prime. #For each random number, test to see if it is prime using #the is_prime() function you wrote in the Prime Numbers lab. #If the number is prime, append it to the prime list; #if the number is non_prime, append it to the non_prime lis
import random
#Constant for rows ROW = 20 primes = [] non_primes = []
def main (): #creating list value = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
#Filling the list with randome questions for r in range (ROW): value[r]= random.randint(1,100) print(value)
specific_statistic(value) is_prime(value) def specific_statistic(value_list):
#printing out the min print('The Lowest: ',min(value_list))
#printing out the max print('The Highest: ',max(value_list))
#calculaing the average total_1 = 0.0
for number_1 in value_list: total_1 += number_1 average = total_1/ len(value_list) print('The Average: ', average)
#calculating the sum total_2 = 0 for number_2 in value_list: total_2 += number_2
print('The sum: ',total_2)
def is_prime (value_list1): # compute primeness for n in value_list1: prime = True if n == 2: prime = True else: for i in range(2, n): if n % i == 0: prime = False break
if prime: print(primes.append(value_list1)) else: print(non_primes.append(value_list1))
main()
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