Python Exercises: Check if each number is prime in a list of numbers
Check If All Numbers Are Prime
Write a Python program to check if each number is prime in a given list of numbers. Return True if all numbers are prime otherwise False.
Sample Data:
([0, 3, 4, 7, 9]) -> False
([3, 5, 7, 13]) -> True
([1, 5, 3]) -> False
Sample Solution-1:
Python Code:
Sample Output:
Original list of numbers: [0, 3, 4, 7, 9] Check if each number is prime in the said list of numbers: False Original list of numbers: [3, 5, 7, 13] Check if each number is prime in the said list of numbers: True Original list of numbers: [1, 5, 3] Check if each number is prime in the said list of numbers: False
Flowchart:
Sample Solution-2:
Python Code:
Sample Output:
Original list of numbers: [0, 3, 4, 7, 9] Check if each number is prime in the said list of numbers: False Original list of numbers: [3, 5, 7, 13] Check if each number is prime in the said list of numbers: True Original list of numbers: [1, 5, 3] Check if each number is prime in the said list of numbers: False
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to find all prime numbers in a given list.
- Write a Python program to count the number of prime numbers in a list.
- Write a Python program to check if a list contains more prime numbers than non-prime numbers.
- Write a Python program to find the sum of all prime numbers in a given list.
Go to:
Previous : Generate Square Numbers in Range
Next :Generate All List Permutations
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.