I've worked through the code now and understand it, although I struggled initially, especially. Let's suppose n is given a value of 10. This means:
- List = range(-1,109,2) = (-1, 1, 3, 5, ..., 107, 108)
- while List[i:] = List[2:] = (3, 5, ..., 107, 108) because initially i has a value of 2
- List[List[i]::List[i]] = List[List[2]::List[2]] = List[3, 5, ..., 107, 108]
- i+=1 means that value of i, will increment by 1, as the while loop is traversed
The while loop will continue as long as List[i:] is True but eventually the i will be greater than the length of List and List[:i] will be FALSE. In SageMathCell, things look like this:
The above code is purely Python and doesn't used any SAGE code at all. As far as I know, there's no command in the latter that will generate lucky numbers (as can be done for prime numbers). There are 82 exercises with solutions at the W3resource site. It would be instructive to attempt some of these.
No comments:
Post a Comment