$29.99
Create two sequences of directories,
• ~/COMP9021/Labs and
• ~/COMP9021/Lectures.
One way to do this is to, in your home directory, execute the Unix command mkdir -p COMP9021/Labs COMP9021/Lectures
Download from the course’s website the compressed archives
• Lab_1.tar.gz and
• Lecture_1.tar.gz,
and save them in the appropriate directories. Decompress the archives. One way to do this is to, in the directory ~/COMP9021/Labs, execute the Unix command tar xzf Lab_1.tar.gz and in the directory ~/COMP9021/Lectures, execute the Unix command tar xzf Lecture_1.tar.gz
This will create a subdirectory Lab_1 of ~/COMP9021/Labs and a subdirectory Lecture_1 of ~/COMP9021/Lectures, each of which will contain the provided material. The archives can then be deleted. One way to do this is, in the directory ~/COMP9021, execute the Unix command rm Labs/*gz Lectures/*gz
You will do the same for the following labs and lectures; recall then to refer to these instructions if needed.
1 Running python code
2 Text-based programs
2.1 Arithmetic computations
Run and study the program fahrenheit_to_celsius.py.
Then write a program celsius_to_fahrenheit.py that displays a conversion table from Celsius degrees to Fahrenheit degrees, with the former ranging from 0 to 100 in steps of 10.
2.2 Lists
Run and study the program max_in_list.py.
Then write a program largest_difference.py that generates a list of 10 random integers between -50 and 50 (included), prints out the list, computes the maximum difference between 2 successive elements in the list, and prints it out. Here is a possible interaction:
$ python largest_difference.py
The list is: [29, -18, -21, -46, 32, -46, -10, -19, 31, 40]
The maximum difference between successive numbers in this list is: 78
$ python largest_difference.py
The list is: [-17, -45, -28, -25, -48, 4, 29, -43, -1, 40]
The maximum difference between successive numbers in this list is: 52
$ python largest_difference.py
The list is: [20, -16, 20, -44, 41, 31, 32, -2, -15, -40]
The maximum difference between successive numbers in this list is: 85
3 Drawing pictures with turtle
For the following exercises, you can refer to the Turtle graphics documentation, but you can complete the exercises by just studying the sample programs.
3.1 An hexagram
Run and study the program dodecagrams.py.
Then write a program hexagram.py that draws an hexagram that is centred horizontally in the window that displays it, with the colour of the tips alternating red and blue:
You are encouraged to draw the red part and then the blue part of the star.
3.2 An octagram
Run and study the program dodecagon.py.
Then write a program octagram.py that draws an octagram, the inscribed octagon being coloured yellow, and the colour of the triangles alternating red and blue:
You can set the distance from the centre to an edge of the inscribed octagon to 100 pixels, and the distance from the centre to the tip of a triangle to 180 pixels.