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!
Similar Kata:
Stats:
Created | Apr 21, 2017 |
Published | Apr 21, 2017 |
Warriors Trained | 1013 |
Total Skips | 26 |
Total Code Submissions | 2363 |
Total Times Completed | 448 |
Python Completions | 448 |
Total Stars | 14 |
% of votes with a positive feedback rating | 83% of 149 |
Total "Very Satisfied" Votes | 109 |
Total "Somewhat Satisfied" Votes | 29 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 12 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |