
Python | Print prime no between 1 to 100
This is an example of how to print all prime numbers between 1 and 100 using for loop.
A prime number is a natural number greater than 1 which has no other factors except 1 and the number itself.
The first few prime numbers are {2, 3, 5, 7, ….}
n = 100
total = 0
for i in range(2, n):
flag = True
for j in range(2,i):
if i%j == 0:
flag = False
break
if(flag == True):
total +=1
print(i)
print(f'total no of prime between 1 to {n} is {total}')
Output for the above code:
>>> ================== RESTART: E:\py\prime_no_1_to_100.py ================== 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 total no of prime between 1 to 100 is 25