Use the function to find all the prime numbers in 100-200 (including 100 and 200)

Question : Use a function to find all the prime numbers in 100-200? Print these prime numbers. 

Analysis: What is a prime number? A prime number is a number that is only divisible by 1 and itself. How to check if a number is prime. Now let me give you an idea, that is, from 100 to 200, judge the prime numbers one by one. If it is a prime number, print it, otherwise it will not print.

 

#Find the prime numbers between 100 and 200
def calc_num():
	for i in range(100,201):#The value obtained is: 100~200 (including 100 and 200)
		fg = 0 # Marking Yes / No Prime number, 0 prime number, 1 non-prime number
		for j in range(2,i-1): #Key point, filter to 1 and itself, and get 2~199 (including 100 and 199)
			if i%j == 0:#The divisible number is definitely not a prime number
				fg = 1
				break
		if fg == 0: # prime number
			print(i)          

calc_num()

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327060575&siteId=291194637