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 18:30
Word vocabulary words: print, proofread, status line, graphics, font effects, left margin, justification, line spacing, copy/paste, data. review words: font point, bold, save, center, error. fill in the correct word for the definition and then transfer the letters to the appropriate spot by number. some numbers will be found multiple times. you will end up with a quotation about…… what else? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 k 16 17 18 19 20 21 22 23 24 25 8 27 28 29 w 31 32 k 34 35 36 w h 39 40 41 42 8 44 45 46 47 48 49 50 51 52 53 54 55 .1. a software function that records keystrokes on a disk or drive so information can be 5 4 52 9 later retrieved. p n 2. to produce a paper copy of information. 10 7 12u n 3. a display that shows the location of the cursor, pages, etc. 45 46 18 27 36 20 42p4. pictures or images, located in clip art or other files. 6 24 44 28 34 49 555. any mis-stroke of a key. 47 41 48 2 10 n6. allows major changes to the font such as shadow, emboss, etc. 21 25 46 35 23 21 29 14 22 17 n7. a feature that centers lines of text horizontally. 49 53 46 9 51 p8. size of the font 31 16 22 b l 9. a feature that prints designated text darker than the rest to add emphasis. 32 3 . p10. to compare copy on a display screen or printout to the original 24 39 25 23 54 9 50 3 and correct errors. j un 11. a feature that allows text to be aligned at the left 11 12 7 21 16 49 40 46 34 2 and right margins. leftn 12. amount of blank space on the left side of the paper. 8 18 41 6 34 linen 13. number of blank lines between lines of text. 17 4 49 13 1914. any information inputted into the computer. 3 4 46 44 p /p15. feature that duplicates text from one location and places it in another.
Answers: 2
question
Computers and Technology, 23.06.2019 16:30
What is one reason why indoor air pollution has become an increasing problem.
Answers: 1
question
Computers and Technology, 24.06.2019 20:20
Write python code that prompts the user to enter his or her age and assigns the user’s input to an integer variable named age.
Answers: 1
question
Computers and Technology, 24.06.2019 20:30
How is energy expended in active transport
Answers: 1
You know the right answer?
Python programming: 2.8 exampledef factors(n): factorlist = []k = 2while k< =nwhile n%k==0: facor...
Questions
Questions on the website: 13722363