python program to print prime numbers upto n
#python program to print prime numbers upto n #python #programmer #pythonQuestion #learnPython
Prime number is define as whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1 (e.g. 2, 3, 5, 7, 11):
Here we need to create variable and put the value in loop .
The for loop ranges from 2 to the half of the number so 1 and the number itself are not counted as divisors.
then we can check the two condition are follow :
primeVariable=int(input("Enter upper value to print prime numbers n : ")) for a in range(2,primeVariable +1): k=0 for i in range(2,a//2+1): if(a%i==0): k=k+1 if(k<=0): print(a)
Enter upper limit: 30
2
3
5
7
11
13
17
19
23
29
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97.
To find whether a larger number is prime or not, sum all the digits in a number, if the sum is divisible by 3 so it is not a prime number. There is except 2 and 3 in our input, all the other prime numbers can be present in the general form as 6n + 1 or 6n - 1, where n is the natural number.