About 484,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): result.append(i) return find_primes(n, i+1, result) Output. Also, you can simplify for loops using list comprehension.

  2. Recursive program for prime number - GeeksforGeeks

    Jan 27, 2022 · In this article, you will see how you can write the logic of stored procedure to generate prime numbers for any given input. Title : Given a number N print all the prime number (<=N) separated by comma (, ) using Stored Procedure in MYSQL. Example-1 : Input : N = 10 Output : 2, 3, 5, 7 Example-2

  3. How do I find a prime number using recursion in Python

    May 8, 2016 · I have to find out whether number (N) is a prime or not using recursion, no loops are allowed. I've tried converting the usual code that uses a for loop to a recursive one, but it's not behaving the same.

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

    Aug 19, 2021 · You can check for all prime numbers using the Prime function. Simply pass the number as th3 argument. i=2 def Prime(no, i): if no == i: return True elif no % i == 0: return False return Prime(no, i + 1)

  5. Check Prime Number in Python - GeeksforGeeks

    Apr 10, 2025 · We can also find the number prime or not using recursion. We can use the exact logic shown in method 2 but in a recursive way. Explanation: Base condition: The recursion ends when the iterator i reaches 1 or 2, returning True because numbers 1 and 2 are prime.

  6. 7 Methods to Check Prime Numbers in Python | Step-by-Step …

    Jan 22, 2025 · Discover 7 simple and effective methods to check prime numbers in Python. Learn step-by-step approaches, including loops, functions, and advanced techniques.

  7. Analysis of Different Methods to find Prime Number in Python

    Oct 18, 2022 · Here, we will discuss how to optimize your function which checks for the Prime number in the given set of ranges, and will also calculate the timings to execute them. Going by definition, a Prime number is a positive integer that is divisible only by …

  8. Python Programs to Check Prime Number - PYnative

    Mar 31, 2025 · Initialize a variable n with the number to check for prime number and is_prime flag to False. If the number is less than or equal to 1, it’s not prime. Return False. If the number is 2, it’s prime. Return True. Use a for loop to iterate through all integers from 2 up to n-1 (excluding n) using range() function.

  9. 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.

  10. Python Program to Check Prime Number

    Program to check whether a number entered by user is prime or not in Python with output and explanation…