Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2023-24 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menù personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2023-24 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

Exercise 26/10

d
davidedeblasio (1450 points)
6 14 23
in Programming in Python by (1.5k points)
recategorized by
  • Write a function that gets an int n and creates a list with all the integers from 0 to n. Then, starting from 2, it removes from the list all the multiples of the list elements. The function returns the list with the remaining elements.
in the text of the problem it is indicated to remove the multiples but I did not understand which ones, of 2?
190 views
closed with the note: solved

2 Answers

e
enricomaria.follega (1460 points)
9 18 29
by (1.5k points)
"removes from the list all the multiples of the list elements"

I suppose you have to remove the multiples of 2, then those of 3, then those of 5 then those of 7 and so on. Thus the final list should be just the prime numbers.
francesco.calzona (5210 points)
5 20 81
by (5.2k points)
I think that the process is more or less: starting from 2, remove all the elements divisible by 2 in the list; then, do the same operation with, as a divisor, the number immediately next to 2 in the list; then with the number immediately next to this one and so on. It is quite clear that the left out numbers are only prime numbers up to N.