YouTip LogoYouTip

Python Exercise Example12

# Python2.x Python Exercise Instance 12 [![Image 3: Python 100 Examples](#) Python 100 Examples](#) **Question:** Determine how many prime numbers there are between 101 and 200, and output all prime numbers. **Program Analysis:** The method to determine a prime number: divide the number by all integers from 2 to sqrt(this number). If it can be divided evenly, it indicates that this number is not a prime number; otherwise, it is a prime number. Program source code: ## Instance(Python 2.0+) ```python #!/usr/bin/python # -*- coding: UTF-8 -*- h = 0 leap = 1 from math import sqrt from sys import stdout for m in range(101,201): k = int(sqrt(m + 1)) for i in range(2,k + 1): if m % i == 0:
← Python Exercise Example13Python Exercise Example11 β†’