Write a function to compute the prime numbers up to a given value.

Words: 125
Pages: 1
Subject: Uncategorized

Python

The purpose of this assignment is the application of queues.

A prime number is a positive integer other than 1 and is divisible only by 1 and itself. For example, 7 is a
prime number because the only positive factors of 7 are 1 and 7. On the other hand, 12 is not a prime number
because 2, 3, 4, and 6 are also factors of 12.

You are asked to write a function to compute the prime numbers up to a given value. The function is named
sieve and it will take an integer value as parameter. The function should return a list that contains all prime
numbers up to (and including, if appropriate) value, the numbers in the returned list must be in ascending order. def sieve(value):

For example:
• sieve(10) ➔ [2, 3, 5, 7]
• sieve(11) ➔ [2, 3, 5, 7, 11]
• sieve(20) ➔ [2, 3, 5, 7, 11, 13, 17, 19]
• sieve(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]