Page 223 - Bilgisayar Bilimi | Kur 1
P. 223
return False
trial _ factor = 3
root = sqrt(n)
while trial _ factor <= root:
if n % trial _ factor == 0:
return False
trial _ factor += 2
return True
def prime _ sequence(begin, end):
for value in range(begin, end + 1):
if is _ prime(value):
yield value
def main():
primes = list(prime _ sequence(20, 50))
print(primes)
if _ _ name _ _ == ‘ _ _ main _ _ ’:
main() # Run the program
Ekran Çıktısı
[23, 29, 31, 37, 41, 43, 47]
10.8. * Operatörü ile Liste Oluşturma
def main():
a = [0] * 10
print(a)
a = [3.4] * 5
print(a)
a = 3 * [‘ABC’]
print(a)
a = 4 * [10, 20, 30]
print(a)
n = 3 # Use a variable multiplier
a = n * [‘abc’, 22, 8.7]
print(a)
main()
222