Python: Identify nonprime numbers between 1 to 100
Python Basic - 1: Exercise-116 with Solution
Write a Python program to identify non-prime numbers between 1 and 100 (integers). Print the non-prime numbers.
import math def is_not_prime(n): ans = False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: ans = True return ans print("Nonprime numbers between 1 to 100:") for x in filter(is_not_prime, range(1, 101)): print(x)
Nonprime numbers between 1 to 100: 4 6 8 9 10 12 14 15 .. 90 91 92 93 94 95 96 98 99 100
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to generate and prints a list of numbers from 1 to 10.
Next: Write a Python program to make a request to a web page, and test the status code, also display the html code of the specified web page.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join