0% found this document useful (0 votes)
9 views4 pages

Exercise0 Problem

The document outlines an exercise involving the creation of a Python program to manage a user blocklist for a website. It consists of three main tasks: importing and printing unique usernames from a blocklist file, identifying and printing blocked users from a list of visitors, and appending a new offender's username to the blocklist. The exercise emphasizes the use of exception handling and basic Python programming skills.

Uploaded by

Wong Zhunhao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Exercise0 Problem

The document outlines an exercise involving the creation of a Python program to manage a user blocklist for a website. It consists of three main tasks: importing and printing unique usernames from a blocklist file, identifying and printing blocked users from a list of visitors, and appending a new offender's username to the blocklist. The exercise emphasizes the use of exception handling and basic Python programming skills.

Uploaded by

Wong Zhunhao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like