Latest web development tutorials

Python innesca uscita entro il campo specificato

Document Object Reference Esempi python3

Primes (numero primo), noto anche numero primo, ci sono un numero infinito. Tranne 1 e stessa non è altro divisibili divisore.

Gli esempi che seguono possono essere numeri primi di uscita entro un intervallo specificato:

#!/usr/bin/python3

# 输出指定范围内的素数

# take input from the user
lower = int(input("输入区间最小值: "))
upper = int(input("输入区间最大值: "))

for num in range(lower,upper + 1):
	# 素数大于 1
	if num > 1:
		for i in range(2,num):
			if (num % i) == 0:
				break
		else:
			print(num)

Il programma precedente, l'uscita è:

$ python3 test.py 
输入区间最小值: 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
97

Document Object Reference Esempi python3