We'll be building a very simple program in Codeskulptor.

1. Hold Ctrl (on windows) and Click this link --> http://www.codeskulptor.org/ to open it in a new browser tab.

On the page, it shows up with some sample code in the left window. Delete all that code. We'll be adding our own code.

2. Insert the below code.

Code: Select all

```
import random
print random.randrange(0,3)
```

The first line "import random" simply tells the program to import/include a library called "random" which gives us functions/methods that we can use to get random numbers.

In the second line, "print" just prints whatever we tell it to print, and "random.randrange(0,3)" uses the function/method randrange that belong to the "random" library, passing in parameters 0 and 3, which will return a random number from 0 to 3 (excluding 3).

So for example if we wanted to print out random number between 0 and 10, we can use "random.randrange(0,11)".

4. Now delete the code we have and use this code

Code: Select all

```
import random
numbers = []
numbers.append(1)
numbers.append(3)
numbers.append(5)
print numbers
```

Looking at the code, the first line we know about but we don't use it in this program because we're not calling random anything.

The second line defines an empty list called "numbers". In Codeskulptor, an empty list is "[]".

The third, fourth and fifth lines just keep adding a number to our list. We first add 1 to the list, so it's "[1]" then we add 3 to end of list so it's "[1,3]"

and then we add 5 to end of list so it's "[1,3,5]". Then the last line simply prints out result so we can see on the Right window.

6. Now delete the code we have and use this code

Code: Select all

```
import random
number = 0
while number < 10:
print number
number = number + 1
```

8. Now delete that code and use the below code.

Code: Select all

```
import random
numbers = [1,3,5]
if 2 in numbers:
print "2 is in list"
else:
print "2 is not in list"
```

10. Click play to run the code and you'll see that it prints out "2 is not in list" because 2 isn't in our list [1,3,5].

11. Delete the code and use the below code.

Code: Select all

```
import random
numbers = [6,2,4]
my_sorted_list = sorted(numbers)
print my_sorted_list
```

13. Run program by clicking play button, and you'll see the printed list (on right window) is a sorted list of "numbers" variable.

14. Delete the code and use the below code.

Code: Select all

```
import random
numbers = [1,2,3,4,5]
print len(numbers)
```

16. Okay, now we know enough to write a simple Lottery Quick Pick Generator.

17. Delete the code and use code below

Code: Select all

```
import random
numbers = []
while len(numbers) < 6:
new_number = random.randrange(0,49)+1
if new_number not in numbers:
numbers.append(new_number)
print sorted(numbers)
```

First line imports/includes random library.

Next line defines a variable called "numbers" which holds the empty list "[]"

Then the next line we do a while (length of numbers) is less than 6:

Next line (inside the while loop) we set a variable called "new_number" to hold a random number between 0 and 49 (excluding 49) with 1 added to it so the result is a number between 1 and 49 (inclusively).

Next line, we do an "if" check to see if "new_number" is not in our "numbers" list then the next line runs if the condition is true.

Next line, we append the new_number to our "numbers" list.

So basically this whole while loop keeps generating random numbers, and adds it to list if it's not already in our list and this loops stops when length of list is equal to 6 because (len(numbers < 6) is no longer true.

Then finally we print out our numbers list using the learned "sorted" function/method.

19. Click play a few times to see that each time we click play, it generates a different set of sorted numbers which can be used for lotteries where you choose 6 numbers out of 49 (like the Canadian Lottery 6/49).

20. Congratulations, now you're a programmer.

Extra notes: Codeskulptor is a Python language interpreter written in Javascript. If you'd like to learn more on doing/programming in CodeSkulptor you can learn about the Python programming language.