About 2,040,000 results
Open links in new tab
  1. How to print prime numbers in python without using for loop …

    May 6, 2018 · Yes, you can use a recursive function: if n//2 < d: return True. if n%d == 0: return False. return prime_number(n, d+1) if i == n + 1: return result. if prime_number(i, 2): …

  2. 6 Best Ways To Check If Number Is Prime In Python

    Aug 19, 2021 · This article will learn how to check if a number is prime or not in Python. Usually, we all know some common methods using library functions or without using library functions.

  3. Finding prime numbers in a list using Python

    Sep 26, 2022 · We can do this using the modulo. The modulus operator (%) in python gives the remainder after division. For example: We can conclude that a number qualifies as a prime …

  4. 5 Best Ways to Create a List of Prime Numbers in Python

    Feb 20, 2024 · This code snippet first defines a function is_prime() that checks the primality of a single number and a second function generate_primes() that uses a list comprehension to …

  5. Python - Program for printing Prime Numbers from the List of Numbers

    Mar 14, 2021 · In this post, We will see how to write a python program for finding prime numbers from the list of numbers in different ways. Output: Prime Number : -> 2, 3, 5, 7, Input: [15, 30, …

  6. How to Find Prime Numbers in a Range Using Python?

    Oct 22, 2024 · Here is a complete Python code to find prime numbers in a range in Python. def is_prime(n): if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False …

  7. python - Finding prime numbers using list comprehention - Stack Overflow

    Jun 25, 2015 · I was trying to generate all prime numbers in range x to y. I tried simple example first: range(10,11) which means to check if 10 is a prime number: Here is my code: prime_list …

  8. How to find nth prime number in python without using function

    Nov 13, 2021 · You'll need a nested loop to determine if a number is prime. There are several ways to do it. Here's a naive one: prime += 1 + prime%2 # next candidate (3,5,... odds) for …

  9. Python : Finding all the prime numbers in a list. What am I …

    May 7, 2025 · Check the code below: prime = [] for i in n: flag = 0. if i==1: flag=1. for j in range(2,i): if i%j == 0: flag = 1. break. if flag ==0: prime.append(i) . return prime. Input: Output: …

  10. Is there a Python library to list primes? - Stack Overflow

    May 23, 2017 · isprime(n) # Test if n is a prime number (True) or not (False). primerange(a, b) # Generate a list of all prime numbers in the range [a, b). randprime(a, b) # Return a random …