To get the output, I have used print(num). At last, it prints the number which is prime.It checks whether there are any positive divisors other than 1 and the number itself. for loop is used for dividing the input number by all the numbers in the range of 2 to number.
Read, Python program to print pattern and How to calculate simple interest in Python? Python program to print prime or not The above code, we can use to print prime numbers in Python. To get the output, I have used print(number). Upper = int(input("Enter the upper value:")) You may also like Check if a number is a prime Python and How to print factorial of a number in Python.Įxample: lower = int(input("Enter the lower value:")) At last, it prints the number which is prime.The break statement is used to come out of the loop as soon we get any positive divisor then no further check is required.Another for loop is used, we are dividing the input number by all the numbers in the range of 2 to number.for loop is used to iterate from lower to upper values.Firstly, we will take two inputs from the user.Let see python program to print prime numbers. First n prime numbers Python Python program to print prime numbers