1n = 20
2primes = []
3
4for i in range(2, n + 1):
5 for j in range(2, int(i ** 0.5) + 1):
6 if i%j == 0:
7 break
8 else:
9 primes.append(i)
10
11print(primes)
1until = 20
2[n for n in range(2, until) if all(n % m != 0 for m in range(2, n-1))]
1# Program to check if a number is prime or not
2
3#too take the input from user use "num: int = int(input('Give the value of num '))"
4num: int = int(input('Give the value of Num: '))
5
6# define a variable felix
7felix = False
8
9# prime numbers are greater than 1
10if num > 1:
11 # check for factors
12 for i in range(2, num):
13 if (num % i) == 0:
14 # if factor is found, set flag to True
15 felix = True
16 # break out of loop
17 break
18
19# check if flag is True
20if felix:
21 print(num, "is not a prime number")
22else:
23 print(num, "is a prime number")
1import math
2a=[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)))]]
3print(a)
1from math import sqrt
2for i in range(2, int(sqrt(num)) + 1):
3 if num % i == 0:
4 print("Not Prime")
5 break
6 print("Prime")
7
8# Note: Use this if your num is big (ex. 10000 or bigger) for efficiency
9# The result is still the same if the num is smaller