Coventry University Logo
4061CEM - Programming and Algorithms 1
  • File Handling
    2

File Handling

Before you attempt this activity, it is best that you review lecture video two from week six. You can find the video and slides on the module page.

For this activity you will be using the integrated development environment recommended by the module leader. If you need to set up your development environment, it is recommended that you check out the instructions from activity four of week one.

Are You Struggling?

If you have trouble with any of the tasks or want to check your answers are correct, then please make yourself known to a member of staff.

Task 1

For this task you need to create a function that exports the alphabet in bother lower- and upper-case. The alphabet should be exported to a file called 'alphabet.txt', and the contents of the file should look something like:

aA
bB
cC
..
xX
yY
zZ

Task 2

For this task you need to supply a function that reads each row of the supplied CSV file, called modules.csv.

The function should return a list that consists of a dictionary type, for each module in the file. An example of the output expected is provided below.

[
    {'code': '4056CEM', 'title': 'Introduction to Web Development', 'leader': 'Marwan Fuad'},
    {'code': '4059CEM', 'title': 'Legal and Ethical Foundations', 'leader': 'Terry Richards'},
    {'code': '4061CEM', 'title': 'Programming and Algorithms 1', 'leader': 'Ian Cornelius'},
    {'code': '4063CEM', 'title': 'The Security Professional', 'leader': 'Terry Richards'},
    {'code': '4064CEM', 'title': 'Foundations of Cyber Security', 'leader': 'Xiang Fei'}
]
Hint

For this task you will need to use a module called csv to assist in writing your solution. You may want to revisit the lecture video two from this week.