Ask Question
1 May, 01:24

Produce a list named prime_truths which contains True for prime numbers and False for nonprime numbers in the range [2,100]. We provide a function is_prime to assist you with this. Call it like this: is_prime (5). Use lambda, map, filter, and list comprehensions as you see fit. You should not need to use a conventional for loop outside of a comprehension.

+3
Answers (1)
  1. 1 May, 02:55
    0
    def is_prime (n) : for i in range (2, n) : if (n % i = = 0) : return False return True prime_truths = [is_prime (x) for x in range (2,101) ] print (prime_truths)

    Explanation:

    The solution code is written in Python 3.

    Presume there is a given function is_prime (Line 1 - 5) which will return True if the n is a prime number and return False if n is not prime.

    Next, we can use the list comprehension to generate a list of True and False based on the prime status (Line 7). To do so, we use is_prime function as the expression in the comprehension list and use for loop to traverse through the number from 2 to 100. The every loop, one value x will be passed to is_prime and the function will return either true or false and add the result to prime_truth list.

    After completion of loop within the comprehension list, we can print the generated prime_truths list (Line 8).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Produce a list named prime_truths which contains True for prime numbers and False for nonprime numbers in the range [2,100]. We provide a ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers