# (Python Example for Citizen Data Scientist & Business Analyst)

Write a Python program to print the first n Lucky Numbers.

Lucky numbers are defined via a sieve as follows.
Begin with a list of integers starting with 1 :
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, . . . .
Now eliminate every second number :
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, …
The second remaining number is 3, so remove every 3rd number:
1, 3, 7, 9, 13, 15, 19, 21, 25, …
The next remaining number is 7, so remove every 7th number:
1, 3, 7, 9, 13, 15, 21, 25, …
Next, remove every 9th number and so on.
Finally, the resulting sequence is the lucky numbers.

Following animation demonstrating the lucky number sieve. The numbers in red are lucky numbers.

Sample Solution:

Python Code:

``````
n=int(input("Input a Number: "))
List=range(-1,n*n+9,2)
i=2

while List[i:]:List=sorted(set(List)-set(List[List[i]::List[i]]));i+=1
print(List[1:n+1])
``````

Sample Output:

```Input a Number: 10
[1, 3, 7, 9, 13, 15, 21, 25, 31, 33]```

# Special 95% discount

## 2000+ Applied Machine Learning & Data Science Recipes

### Portfolio Projects for Aspiring Data Scientists: Tabular Text & Image Data Analytics as well as Time Series Forecasting in Python & R

```
Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.```