About 1,440,000 results
Open links in new tab
  1. How to Print Prime Numbers from 1 to N in Python? - Python

    Oct 16, 2024 · Here is the complete Python code to print prime numbers from 1 to n in Python. if num <= 1: return False. for i in range(2, int(num**0.5) + 1): if num % i == 0: return False. return True. for num in range(2, n + 1): if is_prime(num): print(num)

  2. Program to print prime numbers from 1 to N. - GeeksforGeeks

    Oct 8, 2024 · First, take the number N as input. Then check for each number to be a prime number. If it is a prime number, print it. Approach 1: Print prime numbers using loop. Now, according to formal definition, a number ‘n’ is prime if it is not divisible by any number other than 1 …

  3. To find first N prime numbers in python - Stack Overflow

    Whilst playing with prime numbers in Python V3 I noticed that the smallest number by which a composite(non-prime) number is divisible is itself always a prime that is less than the square root of the number under test. Below is my implementation of that …

  4. Check Prime Number in Python - GeeksforGeeks

    Apr 10, 2025 · Given a positive integer N, the task is to write a Python program to check if the number is Prime or not in Python. For example, given a number 29, it has no divisors other than 1 and 29 itself. Hence, it is a prime number.

  5. Python Program to Check Prime Number

    You can change the value of variable num in the above source code to check whether a number is prime or not for other integers. In Python, we can also use the for...else statement to do this task without using an additional flag variable.

  6. Generate and print first N prime numbers - GeeksforGeeks

    Mar 30, 2023 · Given a number N, the task is to print the first N prime numbers. Examples: The problem can be solved based on the following idea: Start iterating from i = 2, till N prime numbers are found. For each i check if it is a prime or not and update the count of primes found till now. Follow the steps mentioned below to implement the idea:

  7. Python Program For Prime Number Using Function (With Code)

    The is_prime() function takes a number n as an argument and returns True if it is a prime number, and False otherwise. Here’s a step-by-step explanation of the code: If the number n is less than 2, it is not a prime number.

  8. How to Check if a Number is Prime in Python? - Python Guides

    Oct 20, 2024 · One of the simplest ways to check if a number is prime or not in Python is by iterating from 2 to n-1 and checking if n is divisible by any of these numbers. Here is an example of the complete Python program. if n <= 1: return False. for i in range(2, n): if n % i == 0: return False. return True.

  9. Python Programs to Find Prime Numbers within a Range - PYnative

    Mar 31, 2025 · If the number is prime, we add it to the list primes. This method is inefficient for larger numbers because of unnecessary modulo operation till num. 2. Optimized Method (Check up to √n) In this Python method, instead of checking divisibility up to the number itself, we only need to check up to the square root of the number.

  10. Python Programs to Print Alternate Prime Numbers till N

    Apr 8, 2025 · A Prime Number is a number that can only be divided by itself and 1 without remainders (e.g., 2, 3, 5, 7, 11).. This article covers a Python programs that prints alternate prime numbers up to a given number n.We have discussed the various methods, each with an example and detailed explanation.

  11. Some results have been removed
Refresh