7 kyu

Simple Prime Number Generator

Description:

Your task here is to generate a list of prime numbers, starting from 2.

One way of doing this is using python's generators.

In case you choose to use generators, notice that the generator object should contain all the generated prime numbers, from 2 to an upper limit (included) provided as the argument to the function. If the input limit is less than 2 (including negatives), it should return an empty list.

Each iteration of the generator will yield one prime number. See this link for reference.

The generator object will be converted to a list outside the code, within the test cases.

There will be no check if you are using generators or lists, so use the one you feel more confortable with.

Examples

Some expected results:

list(generate_primes(10)) = [2, 3, 5, 7]
list(generate_primes(23)) = [2, 3, 5, 7, 11, 13, 17, 19, 23]
list(generate_primes(28)) = [2, 3, 5, 7, 11, 13, 17, 19, 23]
list(generate_primes(-1)) = []

Good luck!

Algorithms

More By Author:

Check out these other kata created by Raphango

Stats:

CreatedApr 21, 2017
PublishedApr 21, 2017
Warriors Trained1013
Total Skips26
Total Code Submissions2363
Total Times Completed448
Python Completions448
Total Stars14
% of votes with a positive feedback rating83% of 149
Total "Very Satisfied" Votes109
Total "Somewhat Satisfied" Votes29
Total "Not Satisfied" Votes11
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Raphango Avatar
  • anter69 Avatar
  • saudiGuy Avatar
Ad