# 2807/7001ICT | Programming Principles | Programming

Home Recent Questions 2807/7001ICT | Programming Principles | Programming

1    Preparation

•    Read all of this document.
•    Review the lecture notes sections 1 to 20.
•    Bring some paper (a print-out of this document is best) and writing implements.
•    Bring a storage device, such as a portable hard drive and cable, or a USB drive.

2    Pre-workshop questions (1 mark)

Complete these questions in writing before the start of the workshop. They will be marked early in the workshop.

1. Give two di erences between a tuple and a list.
2. Give an important di erence between an array in an older language, such as C, and a list in Python.
3. Complete this table, if the following statements have already been executed. Try to work it out yourself, before con rming with the REPL.

i = 3

s = 'robin'

xs = [5, 4, 3, 2, 1]

t = (i, xs, s, False)
expression    type    value

i    int    3

s[0]

xs[2]

xs[i]

t[3]

xs[-1]

xs[-3]

s[1:]

s[1:3]

s[1:-2]

xs[:-1]

xs[0::2]

t[1][1]

t[2][:-2]

3. Workshop activities

3.1 Marking last workshop's problems

If you have problems that still need marking from the previous workshop, get them marked at the start of this one.

3.2 Problem 1 (1 mark)

Problem: The Unix tool head prints only the top few lines of a le. Write your own version of head that prompts for the name of the le to read, and the number of lines to print. For example:

File name: Lear.txt

Lines: 9

I

The Owl and the Pussy-cat went to sea

In a beautiful pea-green boat,

They took some honey, and plenty of money,

Wrapped up in a five-pound note.

The Owl looked up to the stars above,

And sang to a small guitar,

"O lovely Pussy! O Pussy, my love,

What a beautiful Pussy you are,

If the le has fewer lines than requested, print as many as there are.

Hint: You don't need to store all the lines in memory before printing them.

3.3 Problem 2 (1.5 marks)

This problem and the rest are due at the beginning of the week 9 workshop. Ask any questions you have about the problems now, or in the week 8 workshop.

Problem: The Unix tool wc counts the numbers of characters, words and lines in a le. Write your own version of wc that prompts for the name of the le to read, then prints the counts. For example:

File name: Lear.txt

Characters: 1242

Words: 224

Lines: 38

Hint: You don't need to store all the lines in memory before counting.

3.4 Problem 3 (1.5 marks)

Problem: Write a program that prompts for the name of a le containing numbers, one per line, and prints the average (arithmetic mean) and the median. For example:

File name: scores.txt

Average = 24.5

Median = 25.5

Note: it is intended that you compute the average and the median yourself. You may not use the statistics module.

4. After the workshop

• You have created programs that might be useful to refer back to in future workshops. Make sure that you will have that work in the future. One copy is not enough for at IT professional. You should have at least 2 copies:

1. on your Gri  th network storage drive; and
2. on your portable storage device.
{ What was the best aspect of this workshop?
{ What was the most di cult or worst aspect of this workshop? { Did you nd an error in these workshop notes?

#### Latest Reviews

• ##### Kannon
13 Jul, 2019

I asked for essay help from Assignment Help 4 Me and I am happy that the essay writers completed my task on time. The prices they asked for are worth in comparison to the services rendered.

• ##### Liam
13 Jul, 2019

Assignment Help 4 Me is the best help provider. I took assistance to get my essay completed and I am glad that the writers delivered the quality content as they promised within the time committed.

• ##### Silas
12 Jul, 2019

Accounting is a very interesting subject but when it comes to assignment writing, I feel hard to get through the same. But, since the assignments have to be completed somehow, I preferred to avail online help from Assignment Help 4 Me. All thanks to them that they helped me complete my work on time at reasonable prices.