Repetitive structures – For and While Loops

Now we are going to write a program to put 100 random numbers in a list and sort them.

Let’s start with the pseudocode

Program SortRandomNumbers:

End.

Deliverables for Task 1
• Pseudocode for sort numbers program

Task 2 – Sort number program

Now let’s put together the program. Open the Python IDLE program and create a new program called _PA22 in this Window

Import a module called random

In your program create a list named list[].

Put in a loop that appends 100 random numbers to a list using the function

for i in range(100):
    list.append(random.randint(1,100))

print the list of numbers in its original order

Then we’ll sort the list

list.sort()

print out the sorted list of numbers

Modify the program to have 1000 numbers on the list.

Sample Solution