Python Practice Example 36
Problem:Find prime numbers within 100.
Program analysis:None.
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# Output prime numbers within a specified range
# User input data
lower = int(input("Enter the minimum value of the interval:"))
upper = int(input("Enter the maximum value of the interval:"))
for num in range(lower,upper + 1):
# Prime numbers are greater than 1
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num)
The output of the above example is:
输入区间最小值: 1 输入区间最大值: 100 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97Other extensions
Python 100 Examples