Exercise 0
Many websites keep a user blocklist—a list of users that are blocked from accessing
their services.
Use your basic Python knowledge to write a programme for the following three
problems. Compare your programme with a model solution presented at the end of
this exercise.
Blocked user logo image source: https://commons.wikimedia.org/wiki/File:Blocked_user_PD.svg
EE0005 Introduction to Data Science and Artificial Intelligence – Exercise 2
Q1. Import Blocklist to Python Programme
A very popular website, www.verypopular.com.sg, keeps its blocklist in a text file,
blocklist.txt. In this file, each username occupies a single line. Below is an example of a
blocklist.txt, which you can download from the course website.
Write a Python programme that imports and prints on the screen the usernames from
blocklist.txt. Include an exception handler to catch FileNotFoundError and ensure that
usernames are unique.
EE0005 Introduction to Data Science and Artificial Intelligence – Exercise 3
Q2. Print Usernames of Blocked Users
Below is the list of visitors to www.verypopular.com.sg today.
Print on the screen the number of visitors to the website today. From these visitors,
find those that have been denied access, and print their usernames on the screen.
EE0005 Introduction to Data Science and Artificial Intelligence – Exercise 4
Q3. Add New Offenders to Blocklist
You have discovered that another user violated the site rules today. The username of
the offender is:
You have decided to block the user’s access. Write a Python programme that
appends the new offender to the existing blocklist.txt.
EE0005 Introduction to Data Science and Artificial Intelligence – Exercise 5