About 2,000,000 results
Open links in new tab
  1. Prime number python nested loops - Stack Overflow

    Feb 25, 2014 · I am new to python and I am having some problems with this code that should print all the prime numbers that are smaller than 50 using nested loops. Here is the code: i = 2 while(i < 50): j = 2 while(j <= (i/j)): if not(i%j): break j = j + 1 if (j > i/j): print(i, " is prime") i = i + 1

  2. python - Using nested for loops to generate primes - Stack Overflow

    A nested for loop; the first for loop takes every number between the user's lower and upper bounds and then checks if every one of those numbers is divisible by any of the numbers between 2 and the user's upper bound

  3. Prime Numbers between 2 to 50-Nested Loops - Example Project

    Aug 1, 2023 · This Python code demonstrates the use of nested loops to find prime numbers between the range of 2 to 50. Prime numbers are numbers that are divisible only by 1 and themselves. Code:

  4. python - how to use for loop to calculate a prime number - Stack Overflow

    Nov 11, 2018 · Here's a Python implementation of a well-known algorithm (the Sieve of Eratosthenes) for generating the first n primes (credit to tech.io for the code): primes = 2*[False] + (n-1)*[True] for i in range(2, int(n**0.5+1.5)): for j in range(i*i, n+1, i): primes[j] = False. return [prime for prime, checked in enumerate(primes) if checked]

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

    In this post learn how to print prime numbers in python from 1 to 100, 1 to n, and in a given interval with an algorithm, explanation, and source code.

  6. Nested For Loop in Python - Tutorial Kart

    We can use nested loops to check if numbers in a range are prime. is_prime = True for div in range(2, int(num ** 0.5) + 1): if num % div == 0: . is_prime = False break if is_prime: print(num, end=" ") Explanation: The outer loop (for num in range(2, 21)) iterates through numbers from 2 …

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

  8. Python Program to Print Prime Numbers In a Given Range

    Run a nested while loop to check for prime or not. We do so by checking if the number has any factors in the range [2, sqrt(number)]. Let’s implement the above logic in Python Language.

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

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

Refresh