About 640,000 results
Open links in new tab
  1. Python Program to Check Prime Number using While Loop

    Here is a simple example of how you can use a while loop to check if a number is prime or not in Python: def is_prime(n): if n <= 1: return False i = 2 while i*i <= n: if n % i == 0: return False i += 1 return True # Test the function for n in range(2, 10): print(f"{n}: {is_prime(n)}")

  2. How to Print Prime Numbers from 1 to N in Python? - Python

    Oct 16, 2024 · Print the First 10 Prime Numbers in Python Using a While Loop. Here, let me show you two methods to print the first 10 prime numbers using a while loop in Python. Method 1: Basic While Loop with Prime Check Function. This method uses a while loop to iterate through numbers and a helper function to check if a number is prime. Example:

  3. print prime numbers from 1 to 100 in python – allinpython.com

    6. write a python program to print prime numbers in a given range using a while loop. NOTE: In this program, we will change only the upper limit and lower limit of the while-loop with user input.

  4. How to Find Prime Numbers in Python using While Loop

    How to Find Prime Numbers in Python using While Loop. In this Python tutorial, I want to share source codes of a simple Python program which identifies whether a number is a prime number or a composite number.

  5. Python while loop for finding prime numbers - Stack Overflow

    As a first exercise with Python, I'm trying to write a program using loops to find primes. Everything works with a for loop so I am trying to use a while loop. This works but the program returns a few incorrect numbers. max_num = int(input("max number?: ")) i = 0. # It's only necessary to check with the primes smaller than the square.

  6. Python Beginner's Loop (Finding Primes) - Stack Overflow

    for i in range(2, p): if p % i == 0: break. else: print p, This is perhaps a more idiomatic solution (using a for loop instead of a while loop), and works perfectly. The outer for loop iterates through all the numbers from 2 to n. The inner one iterates to all numbers from 2 to p.

  7. Python Program to Check Prime Number - ScholarHat

    Jan 19, 2025 · print (f"{number} is a prime number.") else: print (f"{number} is not a prime number.") This will involve making a request for your input on a certain number before subjecting it under the mentioned test condition, which causes it to display results as follows. Enter a number: 7 7 is a prime number.

  8. Python Programs to Check Prime Number - PYnative

    Mar 31, 2025 · Explanation:. Edge case: Numbers less than or equal to 1 are immediately classified as not prime because prime numbers are greater than 1. Use of math.sqrt: The math.sqrt function calculates the square root of n.; For Loop: The loop iterates from 2 up to and including √n, significantly reducing the number of checks needed compared to iterating through all numbers up to n-1.

  9. Python Program to Print all Prime Numbers in an Interval

    Source code to print all prime numbers between two numbers enterd by user in Python programming with output and explanation...

  10. Python Program to Print Prime Numbers - CodesCracker

    The question is, write a Python program to print all prime numbers from 1 to 100. The program given below is its answer: for i in range (start, end+1): count = 0. for j in range (2, i): if i%j == 0: count = 1. break if count == 0: print (i)