This is a simple Python script that takes a list of numbers from user input, detects prime numbers, and prints which ones are prime.
- Accepts input in various formats: numbers separated by spaces, commas, or dots
- Automatically filters non-integer input and handles errors
- Efficient prime number detection using square root optimization
When prompted, enter numbers like:
4, 7, 10, 18
Any combination of commas, dots, or spaces will be parsed correctly.
write numbers: 3, 4, 5
3 is prime
4 is not prime
5 is prime
Prime numbers: [3, 5]
- The input string is cleaned using
replace(',', ' ').replace('.', ' '). - The cleaned string is split and converted into integers using list comprehension.
- Each number is checked for primality by trying to divide it by all integers from
2up to the square root of the number. - Results are printed and prime numbers are stored in a list.
- Python 3.x
MIT License β free to use and modify.