subject

Python programming: 2.8 exampledef factors(n): factorlist = []k = 2while k< =nwhile n%k==0: facorlist. append(k)n //= kk += 1return factorlistthe program in example 2.8 is not a very efficient way of calculating prime numbers: it checks each number to see if it is divisible by any number less than it. we can develop a much faster program for prime numbers by making use of the following observations: a) a number n is prime if it has no prime factors less than n. hence we only need to check if it is divisible by other primes. b) if a number n is non-prime, having a factor r, then n = rs, where s is also a factor. if r ≥ √n then n = rs ≥ √ns, which implies that s ≤ √n. in other words, any non- prime must have factors, and hence also prime factors, less than or equal to √n. thus to determine if a number is prime we have to check its prime factors only up to and including √n—if there are none then the number is prime. c) if we find even a single prime factor less than √n then we know that the number is non- prime, and hence there is no need to check any further—we can abandon this number and move on to something else. write a python program that finds all the primes up to ten thousand. create a list to store the primes, which starts out with just the one prime number 2 in it. then for each number n from 3 to 10 000 check whether the number is divisible by any of the primes in the list up to and including √n. as soon as you find a single prime factor you can stop checking the rest of them—you know n is not a prime. if you find no prime factors √n or less then n is prime and you should add it to the list. you can print out the list all in one go at the end of the program, or you can print out the individual numbers as you find them.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:00
Which best describes the condition under which the unicode output is the same as plain text?
Answers: 3
question
Computers and Technology, 22.06.2019 23:50
List a few alternative options and input and output over the standerd keyboard and monitor. explain their functioning in details.
Answers: 2
question
Computers and Technology, 23.06.2019 02:00
Read this excerpt from helen keller’s autobiography, the story of my life. have you ever been at sea in a dense fog, when it seemed as if a tangible white darkness shut you in, and the great ship, tense and anxious, groped her way toward the shore with plummet and sounding-line, and you waited with beating heart for something to happen? i was like that ship before my education began, only i was without compass or sounding-line, and had no way of knowing how near the harbour was. "light! give me light! " was the wordless cry of my soul, and the light of love shone on me in that very hour. . the morning after my teacher came she led me into her room and gave me a doll. the little blind children at the perkins institution had sent it and laura bridgman had dressed it; but i did not know this until afterward. when i had played with it a little while, miss sullivan slowly spelled into my hand the word "d-o-l-l." i was at once interested in this finger play and tried to imitate it. when i finally succeeded in making the letters correctly i was flushed with childish pleasure and pride. running downstairs to my mother i held up my hand and made the letters for doll. i did not know that i was spelling a word or even that words existed; i was simply making my fingers go in monkey-like imitation. in the days that followed i learned to spell in this uncomprehending way a great many words, among them pin, hat, cup and a few verbs like sit, stand and walk. based on this excerpt, which words best describe helen keller?
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Answer these and get 40 points and brainliest
Answers: 1
You know the right answer?
Python programming: 2.8 exampledef factors(n): factorlist = []k = 2while k< =nwhile n%k==0: facor...
Questions
question
Mathematics, 24.10.2020 05:10
question
Mathematics, 24.10.2020 05:10
question
History, 24.10.2020 05:10
question
Mathematics, 24.10.2020 05:10
question
Mathematics, 24.10.2020 05:10
question
English, 24.10.2020 05:10
question
Social Studies, 24.10.2020 05:10