#72 · Math · Intermediate · 65 XP · about 12 min
A prime is a whole number greater than 1 whose only divisors are 1 and itself: 2, 3, 5, 7, 11 and so on.
Write primes_up_to(n) that returns a list of every prime from 2 up to and including n, smallest first. If there are none, return an empty list.
primes_up_to(10) # returns [2, 3, 5, 7] primes_up_to(2) # returns [2] primes_up_to(1) # returns []
Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.