Posts

Showing posts with the label Prime number

Python program to print prime numbers less an inputted number - Codicaly

Image
          In this post, we are going to discuss how to write a python program to print the prime numbers less than an inputted number. We already posted a how-to check whether the inputted number is prime or composite.  I highly recommend reading that and come here by clicking the link below. Link to the post :  https://codicaly.blogspot.com/2021/04/python-program-to-find-given-number-is.html What is a Prime or Composite number ? A prime number is a number that has only two factors i.e, 1, and the number itself.  A composite number is a number that has more than two factors. A number is said to factor that when it divides the other number it leaves no remainder.  Generally, the factors lie between 1 and the number itself. Pre-requisites : Python Basics List Concept Conditional statements ( Nested for-loop ) Program : u=int(input('Enter the upper limit')) for i in range(2,u+1):#Primary for loop     l=[]     for j in range(1...

Python - Program to find the given number is a prime or composite number

Image
  In this post, we are going to check whether an inputted number is a prime number or a composite number. What is a Prime number or a Composite number ?     A prime number is a number that has only two factors i.e, 1, and the number itself.  A composite number is a number that has more than two factors. A number is said to factor that when it divides the other number it leaves no remainder.  Generally, the factors lie between 1 and the number itself. Pre-requisites : Python introduction List concept Conditional statements  Program :  a=int(input("Enter the integer:")) list1=[] # empty list for factors for i in range(1, a+1):     if (a%i==0):         list1.append(i) if len(list1)== 2:     print("The given number ",a," is a prime number.") else :     print("The given number ",a," is a composite number.") Explanation :    1. First, we need to input the integer that we need to find is prime o...