Answers for "primes python"

4

python calculate prime numbers until numer

until = 20
[n for n in range(2, until) if all(n % m != 0 for m in range(2, n-1))]
Posted by: Guest on September-29-2020
1

is_prime in python

# Program to check if a number is prime or not

#too take the input from user use "num: int = int(input('Give the value of num '))"
num: int = int(input('Give the value of Num: '))

# define a variable felix
felix = False

# prime numbers are greater than 1
if num > 1:
    # check for factors
    for i in range(2, num):
        if (num % i) == 0:
            # if factor is found, set flag to True
            felix = True
            # break out of loop
            break

# check if flag is True
if felix:
    print(num, "is not a prime number")
else:
    print(num, "is a prime number")
Posted by: Guest on April-09-2021
3

prime number in python

import math
a=[i for i in range(2,int(input('prime number range'))) if 0 not in [i%n for n in range(2,int(math.sqrt(i)))]]
print(a)
Posted by: Guest on June-18-2021
0

primes python

import math

def main():
    count = 3
    
    while True:
        isprime = True
        
        for x in range(2, int(math.sqrt(count) + 1)):
            if count % x == 0: 
                isprime = False
                break
        
        if isprime:
            print count
        
        count += 1
Posted by: Guest on October-29-2021
-2

prime numbers upto n in python

lower = int(input("Enter lower range: "))  
upper = int(input("Enter upper range: "))  
  
for num in range(lower,upper + 1):  
   if num > 1:  
       for i in range(2,num):  
           if (num % i) == 0:  
               break  
       else:  
           print(num)  
Posted by: Guest on May-01-2020

Python Answers by Framework

Browse Popular Code Answers by Language