[Solved] How do I print lucky numbers? | Sololearn: Learn to code for FREE!

+2

# [Solved] How do I print lucky numbers?

How do I print lucky numbers?

5/9/2017 2:23:29 PM

+1

here is the answer 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])

+8

Go through the list, remove all evens. You can find out if a number is even if it is divisible by 2 using: if(x % 2 == 0) Now, go through the list again but start at the 2nd index or the number 5. Just itterate the for loop by 3 each time and remove each element accordingly. The last step is basically the same as this one except with different numbers.

+2

This is Wikipedia .about lucky numbers 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 Every second number (all even numbers) in the remaining list is eliminated, leaving only the odd integers: 1 3 5 7 9 11 13 15 17 19 21 23 25 The second term in this sequence is 3. Starting with 5, every third number which remains in the list is eliminated: 1 3 7 9 13 15 19 21 25 The next surviving number is now 7. Every seventh remaining number is eliminated, starting with 19: 1 3 7 9 13 15 21 25

+1

You can not print numbers like "Lucky numbers" as there are no such things, but you can print some random numbers, and say them as a lucky number,, using functions such as import random print random.random() can also select from a specific range, randrange(a, b) a is starting limit and b is ending limit number.

+1

https://code.sololearn.com/cHnsZ1ng86F4/?ref=app

0

Thank you all