First of all, try to check all numbers from 2 to n-1. If n is divided by any of the numbers, it is not prime. If a number is prime, print it.
for num in range(2,101):
prime = True
for i in range(2,num):
if (num%i==0):
prime = False
if prime:
print (num)
More pythonic way is:
for num in range(2,101):
if all(num%i!=0 for i in range(2,num)):
print (num)
Or in this manner:
import math
for num in range(2,101):
if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):
print (num)
An improved version is:
import math
print 2
for num in range(3,101,2):
if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):
print (num)
Kindly check Python blog will help you get a better understanding of Automate Your Coding with Python!